How to use Include method in LINQ To Entity when not sure that it has the specified navigation property? -
i give cf example:
public class mycontext : dbcontext { public dbset<a> { get; set; } } public class { public int e { set; get; } } public class b : { public int f { set; get; } } public class c : { public int g { set; get; } public virtual d d { set; get; } } public class d { }
and query this:
using (var context = new mycontext()) { var queryresult = context.a.include("d").select(a => a); }
and throws exception message:
a specified include path not valid. entitytype 'a' not declare navigation property name 'd'.
how solve with 1 linq entity query?
here work around
using (var context = new mycontext()) { var typea=typeof(a); var queryresult ; if( typea.getproperty("d")!=null) queryresult = context.a.include("d").select(a => a); }
Comments
Post a Comment