这个问题在这里已有答案:
我是EF新手,我有以下查询:
List<Test.MemberAccount> userAccounts = new List<Test.MemberAccount>();
using (var context = new CoopEntities1())
{
var query = from s in context.MemberAccount
join sa in context.AccountType on s.account_type_id equals sa.id
where s.member_guid == memberID
select s;
userAccounts = query.ToList();
}
return userAccounts;
问题是当我加载页面时,我收到以下错误:
“ObjectContext实例已被处理,不能再用于需要连接的操作 . ”
任何帮助都会很棒 .
错误详情:
AccountType = '((new System.Collections.Generic.Mscorlib_CollectionDebugView<Test.MemberAccount>
(userAccounts)).Items[0]).AccountType'
threw an exception of type 'System.ObjectDisposedException'
2 回答
您需要为会员帐户eagerly load AccountType:
AccountType没有被急切加载 . 由于您坚持使用查询语法,因此它看起来如下所示:
如果缺少intellisense,请确保包含以下using语句: