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

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -