问题描述
|
如果有2个实体类,ProductEntity和CategoryEntity:
[Table(Name = \"Products\")]
public class ProductEntity
{
// Data Members
private int _productID;
private string _productName;
private int _categoryID;
private EntityRef<CategoryEntity> _category;
// Properties
[Column(DbType = \"int\",IsPrimaryKey = true,IsDbGenerated = true)]
public int ProductID
{
get { return _productID; }
set { _productID = value; }
}
[Column(DbType = \"nvarchar(40)\")]
public string ProductName
{
get { return _productName; }
set { _productName = value; }
}
[Column(DbType = \"int\")]
public int CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
[Association(Storage = \"_category\",ThisKey = \"CategoryID\",OtherKey = \"CategoryID\")]
public CategoryEntity Category
{
get { return _category.Entity; }
set { _category.Entity = value; }
}
} // class ProductEntity
[Table(Name = \"Categories\")]
public class CategoryEntity
{
// Data Members
private int _categoryID;
private string _categoryName;
// Properties
[Column(DbType = \"int\",IsPrimaryKey = true)]
public int CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
[Column(DbType = \"nvarchar(40)\")]
public string CategoryName
{
get { return _categoryName; }
set { _categoryName = value; }
}
} // class CategoryEntity
使用LINQ,我执行如下Select(省略详细信息):
DataContext _northwindCtx = new DataContext(connectionString);
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<ProductEntity>
(ProductEntity => ProductEntity.Category);
_northwindCtx.LoadOptions = loadOptions;
Table<ProductEntity> productsList =
_northwindCtx.GetTable<ProductEntity>();
var productsQuery =
from ProductEntity product in productsList
where product.ProductName.StartsWith(productname)
select product;
List<ProductEntity> productList = productsQuery.ToList();
列表中第一条记录的获得值为
productList[0].ProductName \"TestProduct\"
productList[0].CategoryID 1
productList[0].Category.CategoryID \"1\"
productList[0].Category.CategoryName \"Beverages\"
然后我将CategoryID更新为8
好,到目前为止一切都很好
我重新执行上述选择。
现在第一个记录的获得值
productList[0].ProductName \"TestProduct\"
productList[0].CategoryID 8 OK
productList[0].Category.CategoryID \"1\" ??
productList[0].Category.CategoryName \"Beverages\" ??
ProductEntity的CategoryID属性已更新,但Category属性未更新,换句话说,EntityRef对象尚未被\'rebuild \'???
为什么不?我该如何工作?
谢谢
克里斯
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)