Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF Core - conditionally use .Include

$
0
0

Hi,I need conditionally use .Include,tried something like that:

 var res = db.HT_REZ.AsQueryable();            if (condition) {                res = res.Include(r => r.CF)                       .Include(r => r.HT_ROOM)                       .Include(r => r.HT_GRUPS); }            res = await res.FirstOrDefaultAsync(r => r.ID == id);

but got:  Cannot implicitly convert type 'Rez.Models.HT_REZ' to 'System.Linq.IQueryable<Rez.Models.HT_REZ>'

If I add the conversion   re = (IQueryable<HT_REZ>)await re.FirstOrDefaultAsync(r => r.ID == id) then it doesn't recognize properties

 if (re.ID >100):  'IQueryable<HT_REZ>' does not contain a definition for 'ID'

is there any working solution?

thanks


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>