How to merge from source table to destination table but in source table there is no primary key
how can I insert,update,delete the data from source to destination table
How to merge from source table to destination table but in source table there is no primary key
how can I insert,update,delete the data from source to destination table
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Mar 25, 2023, 6:06 AM
You can use this
Meghana MPosted Mar 25, 2023, 5:53 AM
Data.cs(source class ) no primary and foreign key relationship and column values are same type but names are different between source and destination table
public class Data
{
public string Abc { get; set; }
public string cde { get; set; }
public string efg{ get; set; }
}
Data2.cs(destination class)no primary and foreign key relationship
public class data2
{
public string A_Abc { get; set; }
public string A_cde { get; set; }
public string A_efg{ get; set; }
}
source table
column name :abc,bcd,egf
destination table:
column name:A_abc,A_bcd,A_egf
error:-
'Data table requires a primary key to be defined. If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'
after adding Hasnokey in Data2DBcontext.cs(destination.cs)
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity().HasNoKey();
}
getting invalid column names error
Meghana MPosted Mar 24, 2023, 1:35 PM
source class
public class Data
{
public string Abc { get; set; }
public string cde { get; set; }
public string efg{ get; set; }
}
destination class
public class data2
{
public string A_Abc { get; set; }
public string A_cde { get; set; }
public string A_efg{ get; set; }
}
source table: no primary key
column name :abc,bcd,egf
destination table:
column name:A_abc,A_bcd,A_egf
Stored procedure for truncate and insert data from source to destination
Meghana MPosted Mar 24, 2023, 12:33 PM
ok.Thank you
Naimish MakwanaPosted Mar 24, 2023, 10:16 AM
To perform an insert/update/delete operation on the destination table based on the data from the source table, you can use the following steps:
Use a query to identify the matching records between the source and destination tables. This can be done by comparing the values in one or more columns that are common to both tables. For example, if the tables have a common "Name" column, you can use that column to match records between the tables.
For the records that match between the source and destination tables, perform the appropriate action based on whether the record already exists in the destination table or not.
It's important to note that without a primary key or a unique constraint on a column(s), there may be duplicates or inconsistencies in the data after the merge. Therefore, it's recommended to create a primary key or a unique constraint on the destination table before performing the merge.
Thanks
Jaya PrakashPosted Mar 24, 2023, 5:52 AM
Pls Take Similar Values which u have passed in the first table u should need to match the values with 2nd table