c# - ObjectContext instance has been disposed error -
i new ef , have following query:
list<test.memberaccount> useraccounts = new list<test.memberaccount>(); using (var context = new coopentities1()) { var query = s in context.memberaccount join sa in context.accounttype on s.account_type_id equals sa.id s.member_guid == memberid select s; useraccounts = query.tolist(); } return useraccounts;
problem when load page following error:
"the objectcontext instance has been disposed , can no longer used operations require connection."
any fantastic.
error in detail:
accounttype = '((new system.collections.generic.mscorlib_collectiondebugview<test.memberaccount> (useraccounts)).items[0]).accounttype' threw exception of type 'system.objectdisposedexception'
accounttype not being eagerly loaded. since you're sticking query syntax, following:
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 s.member_guid == memberid select s).include("accounttype"); useraccounts = query.tolist(); } return useraccounts;
if intellisense missing, make sure include following using statement:
using system.data.entity;
Comments
Post a Comment