Click here to Skip to main content
15,881,635 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I want to move or (copy to t2 and delete from t1 )all data from table1 to table2 using Entity Framework, they have the same fields, and most of the answers talk about .Core or asp.net.
I'm using EF6.
Please Help me
Thanks a lot

What I have tried:

var data1 = db.TBL_Collec_Pay.Find();
var data2 = new TBL_Collec_Pay_Ar();
data2.CurrentValue.SetValues(data1);
db.TBL_Collec_Pay_Ar.Add(data2);
db.TBL_Collec_Pay.Remove(data1);
db.SaveChanges();
Posted
Comments
[no name] 14-Mar-23 20:01pm    
"All data"? Then use an SQL proc to copy and truncate.
Dave Kreskowiak 15-Mar-23 0:27am    
Using EF methods to do this, (you're copying one record at a time,) would actually be slower than doing it in pure SQL, and even slightly slower than doing it from a stored procedure in the database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900