c# - When using e.Entity in an EntityDataSource Inserted event, is it good practice to wrap it in using()? -


if i'm doing inserted values during entitydatasource's inserted event, should wrap e.entity in using() statement? can't tell. "in context"?

should (as i've seen in other examples):

myentity newrecord = (myentity)e.entity; myvar = newrecord.datavalue; 

or appropriate practice do:

using (myentity newrecord = new e.entity()) {     myvar = newrecord.datavalue; } 

(don't think syntax totally correct. don't want have how work ask.)

from msdn documentation, can gather e.entity object ... entity. helpful. open new connection , whole rest of package assume new entity require?

in general, i'd yes it. best practice? yes sure. however, answer more "it depends". rule, anytime use object implements idisposable 1 should wrap in using statement unless plan keep object between method invocations.

in stateless world of web (mvc) tend live, try wrap dbcontext in using statement. in winforms/wpf i'm sure there reasons persist until event takes place. these should exceptions rule.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -