C
C#3w ago
Heaven

In EF Core, how do I insert new data to an existing DB with a Migration?

I want to create a migration to insert new data to an existing database deployed in multiple environments. In some environments, devs have already manually inserted the rows. What's the best way of handling this in EF core? Creating a migration that just runs raw insert SQL scripts? And in the raw SQL, check for existence?
6 Replies
mg
mg3w ago
raw sql and maybe consider a MERGE statement?
Heaven
HeavenOP3w ago
If there’s no existing data, should I still raw sql insert it?
mg
mg3w ago
MERGE covers both cases
Heaven
HeavenOP3w ago
are merge statements the standard way of inserting/updating data in migrations?
mg
mg3w ago
idk about standards, but MERGE covers the "if exists do x, if not do y" use case
Heaven
HeavenOP3w ago
yeah I’ll use merge statements, ty! if anyone else can chime in on standard methodology that’d be great too

Did you find this page helpful?