Entity Framework Core Error: “Instance of entity type cannot be tracked because another instance with the same key value”
I’m working on an asynchronous method in C# that inserts a list of records into a SQL Server database using Entity Framework Core. The method is intended to bulk insert data into the database and save the changes.
Is there a way to create foreign keys at runtime in Entity Framework?
For background, let’s say I have two classes:
Executing large number of dynamic EF core queries with only parameter differences in MS-SQL
I’m trying to help optimize performance on some .NET code running against a MSSQL db via EF core, but I’ve never ran into something like this before. This code takes a custom “query” string (proprietary syntax) and converts it into an Expression<Func<T, bool>> for use with EF query (Where predicate). This query string can have 0-5 parameters. In addition to the query string, it will be associated with an array of strings (currently this lives in a file) comma-delimited, with one value per parameter in the query.