How to transfer SQL data from one table to another using Entity Framework Core

.net .net-core c# entity-framework entity-framework-core

Question

In my database, there are two tables with identical columns. History tables TBL one and TBL two. When I am putting data into TBL 1, I want to use EF Core 2.2 to transfer all of the data from TBL 1 to TBL 2 (as historical data).

I don't want to add pointless loops that will make the code seem bad.

var MyEntity = new MyEntities();
var TBL1 = MyEntity.TBL1.Find();
var TBL2 = new TBL2();

TBL2.CurrentValues.SetValues(TBL1); 
//CurrentValues is not accept in code. Giving me build error

MyEntity.TB2.Add(data2);
MyEntity.TB1.Remove(data1);
MyEntity.SaveChanges();

All I need to do is use EF to replicate SQL data from table 1 to table 2 without using loops. Any working example using a mapper or other tool would be helpful.

1
1
4/20/2019 7:58:04 PM

Popular Answer

ZZZ_tmp
0
4/21/2019 10:28:38 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow