这会引发错误,指出查询包含对在不同数据上下文中定义的项目的引用。当我尝试在底部分配 catName 时。
this.CustomSettings = (
from xx in DBContext.ProductCustomizationMasters
where xx.ProductID == this._ProductID
select new ProductCustomization()
{
ProductID = (int)xx.ProductID,
CategoryID = (int)xx.CustomCategoryID,
CustomID = xx.CustomID,
CustomizationType = (CategoryType)xx.CustomType,
DefaultFreeCount = (short)xx.DefaultFreeCount,
IsDefaultLimit = (bool)xx.IsDefault,
HasItems = ((xx.DefaultFreeCount == 0) ? (false) : (true)),
CatName= (from yy in DBContext.CustomCategoryTbls where yy.CatID == xx.CustomCategoryID select yy.CatName).FirstOrDefault()
}
).ToList();
我正在制作这样的数据上下文
private libDBDataContext _DB = null;
public libDBDataContext DBContext { get { return (_DB == null) ? new libDBDataContext() : _DB; } set { _DB = value; } }
它怎么说它有两个不同的数据上下文,而事情是在同一个数据上下文上执行的。