c# - Attaching vs selecting and modifying in L2S -


i have data access layer creates context , retrieves data (with no object tracking) , passes information ui layer:-

my unit of work method , release appdatacontext after executing particular method. not keeping track of data context anywhere..

public  linqobject getobject(){   using (appdatacontext = new datacontext()){   ---code select , return object    } } 

i modify data using form in ui , submit data db.

two approaches are:-

1. detach , reattach different data context using [detach..serialise , attach]   *i have lot of plumping code enable functionality*   2. db object using primary key , make changes in selected object , submitchanges. 

which 1 better approach doing task?

i against moving unit of work data access layer wise or web application life cycle (httpcontext), because dont want track changes , complicate entire application structure unwanted plumping code . using linq making retrieval , updates db easy.

i have never seen discuss these 2 approaches in linq context, why asking best practice.

if don't want go (2) because of performance: option attach new object submit updates.

foo foo=new foo { fooid=fooid }; // create obj , set keys context.foos.attach(foo); foo.name="test"; context.submitchanges(); 

see answer here.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -