c# - Do I need to create a new instance from EntityFramework ObjectContext anytime that I want call query? -
in c# entityframework creating new instance of context this:
using(var context=new dataaccess.myobjectcontext()){ .... }
where myobjectcontext this:
public partial class globalcontext : objectcontext { public globalcontext() : base("name=mydbcontext") //: base(connectionstring) { commandtimeout = 2000; _assetcategory = createobjectset<assetcategory>(); _assetitem = createobjectset<assetitem>(); _assetitemtype = createobjectset<assetitemtype>(); _assetitemmunit = createobjectset<assetitemmunit>(); _filedb_asset = createobjectset<filedb_asset>(); } private objectset<assetcategory> _assetcategory; public objectset<assetcategory> assetcategory { { return _assetcategory; } } private objectset<assetitem> _assetitem; public objectset<assetitem> assetitem { { return _assetitem; } } }
} true create new instance anytime want call query?
the context object idisposable
have dispose of finish working surrounding in using
construct. or make sure class using context in properly implementing idisposable , disposes context too.
Comments
Post a Comment