Sunday, 15 July 2012

c# - "Include" lambda in generic repository -



c# - "Include" lambda in generic repository -

i follow repository pattern , have next method in generic repository class:

public virtual t get(expression<func<t, bool>> where) { homecoming dbset.where(where).firstordefault<t>(); }

i add together lambda look including navigation properties. possible?

here's 1 way it

public virtual iqueryable<t> include(this iqueryable<t> qry, params string[] includes) { foreach(var inc in includes) qry = qry.include(inc); homecoming qry; }

example usage:

var list = context.products.where(x => x.productid == 1).include("items", "person").single();

c# lambda entity-framework-6

No comments:

Post a Comment