c# - How to dynamically generate Includes in entity framework -
well not sure if questions asked before have no idea how search it. not entity framework specified question gonna give example using it.
so in ef need use .include("related object")
include related data. want write method takes list of strings , returns entity or entity list related objects.
in example
public list<entity> getall(list<string> includes>) { list<entity> entites = context.entites; foreach(string s in includes) { entites.include(s); } return entites; }
obviously above example won't work since called out entites when declared list. think demonstrates point.
declare local variable dbquery<entity>
, reassign result of include
call , call tolist
on after loop:
public list<entity> getall(list<string> includes>) { dbquery<entity> entites = context.entites; foreach(string s in includes) { entities = entites.include(s); } return entites.tolist(); }
Comments
Post a Comment