我对以下内容的含义有些困惑:
它们之间有什么区别?
1) AsNoTracking
- 表示没有脏污检查。(与将 EntityState 更改为Detached
?)
2) context.Detach(order)
- (与将 EntityState 更改为Detached
?)
3)NoTracking
急切加载也需要?
creativeWorkshopEntities.Job.MergeOption = MergeOption.NoTracking;
var q = from c in creativeWorkshopEntities.Job.Include("Files")
where c.Id == jobId
select c;
我想做的就是分离实体
我using
的BL class
.
从数据库中填充缓存后,我无法分离实体
因为我仍然在应用程序流中调用它的属性。我猜它会抛出运行时异常(objectContext is desposed
)
你觉得我的逻辑对吗?
public static Group GetMamData(string stamp, MaMDBEntities maMDBEntities)
{
Group group = MamDataCacheManager.GetMamData(stamp);
if (group == null)
{
//was not found in the cache
//check for aveilable test with status 'start' - 1
group = GetGroupsFromDb(stamp, maMDBEntities);
if (group != null)
{
maMDBEntities.Entry(group).State = EntityState.Detached;
MamDataCacheManager.InsertMamData(stamp, group);
}
}
//option B: attache a new context
if (maMDBEntities.Entry(group).State == EntityState.Detached)
{
maMDBEntities.Groups.Attach(group);
}
return group;
}