我有两个类Profile和JobProfile,JobProfile从Profile继承。 我正在使用Entity Framework 6,在dbContext中,我有两个DbSet:
public DbSet<JobProfile> JobProfiles { get; set; }
public DbSet<Profile> Profiles { get; set; }
我还有一个DAL:
public class DAL : IDisposable
{
BddContext db;
public DAL()
{
db = new BddContext();
}
public async Task<ObservableCollection<Profile>> GetProfiles()
{
var oc = new ObservableCollection<Profile>();
var profiles = await(db.Profiles
.Include("FolderInformationAction")
.Include("FolderInformationStore")
.ToListAsync());
foreach (var item in profiles)
{
oc.Add(item);
}
return oc;
}
public async Task<ObservableCollection<JobProfile>> GetJobProfiles()
{
var oc = new ObservableCollection<JobProfile>();
var profiles = await (db.JobProfiles
.Include("FolderInformationAction")
.Include("FolderInformationStore")
.ToListAsync());
foreach (var item in profiles)
{
oc.Add(item);
}
return oc;
}
public void Dispose()
{
db.Dispose();
}
}
当我调用GetProfiles时,它返回Profiles和JobProfiles元素,但是当我调用GetJobProfiles时,它仅返回JobProfiles元素。
所以问题是,我该如何区别两个DbSet?似乎它们已链接。
答案 0 :(得分:0)
我认为TPH默认情况下会这样做。使用它来缩小,或者TPT可以按照定义执行您想要的操作。
var profiles = await(db.Profiles
.Where(q => !(q is JobProfile)
.Include("FolderInformationAction")
.Include("FolderInformationStore")
.ToListAsync());