entity framework 4 - Linq to Entities: How to copy records from one table to another efficiently? -
we have event system organizes data date , time. copy data old event new event starter, modify it.
this in linq:
- get source objects locally .tolist()
- for each item create new object
- copy non-primary key values new object , set new primary key
- add object table
this generates tremendous amount of database calls. it's wrapped in transaction @ least.
this statement in sql. way make linq efficient without embedding sql?
insert targettable (eventid, two, three, 4 five) select @neweventid eventid, two, three, four, 5 targettable eventid = @eventid
no can't make ef code more efficient. how ef works. if want efficiency wrap sql stored procedure, map stored procedure in ef designer , call sp.
if can't create stored procedure execute sql directly. can use:
objectcontext.executestorecommand(...)
this method available in ef4.
Comments
Post a Comment