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

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -