假设我有一个用户(映射到一个用户表),而Edit视图(在MVC中)显示了用户可以访问的模块的多选列表(映射到一个模块表),模块是根据用户的模块EntitySet预先选择的。
我尝试保存用户,然后手动删除所有User_Modules,并根据提交时选择的内容重新添加它们,但用户的User.User_Modules EntitySet为空。
我在网上找不到正确的方法来处理这种情况。有人能帮上忙吗?
编辑:添加我的EntitySet代码
private EntitySet<UserModule> _UserModules;
[Association(Storage = "_UserModules", ThisKey="UserId", OtherKey = "UserId")]
public EntitySet<UserModule> UserModules
{
get { return this._UserModules; }
set { this._UserModules.Assign(value); }
}发布于 2010-03-30 01:49:36
尝试检查是否先加载了该集合
Linq to SQL
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<User>(c => c.User_Modules);
context.LoadOptions = options;
//Do query and then see if your EntitySet is still null.Linq to entities way...
if(!User.User_ModulesReference.IsLoaded){
User.User_ModulesReference.Load();
}
//Insert delete logic here...https://stackoverflow.com/questions/2539112
复制相似问题