using (var dbContext = new SmartDataContext())
{
dbContext.Configuration.ProxyCreationEnabled = false;
var query = dbContext.EntityMasters.OfType<Person>();
if (includeAddress)
query.Include(p => p.Addresses);
if (includeFiles)
query.Include(p => p.FileMasters);
output.Entity = query.Include(s=>s.Addresses).FirstOrDefault<Person>(e => e.EntityId == id);
}
虽然这并不:
using (var dbContext = new SmartDataContext())
{
dbContext.Configuration.ProxyCreationEnabled = false;
var query = dbContext.EntityMasters.OfType<Person>();
if (includeAddress)
query.Include(p => p.Addresses);
if (includeFiles)
query.Include(p => p.FileMasters);
output.Entity = query.FirstOrDefault<Person>(e => e.EntityId == id);
}
我想包括地址,文件基于布尔标志从功能到来。但是,似乎EF在使用IF条件时不包括它们。
这与我的previous问题有关,它使用Include实际工作。
**经验法则:**如果非要说“编辑”把在编辑,那么你并不真正需要编辑。 –