CreateTempTable returning entity in permanent table
See original GitHub issueHi,
I am attempting to copy an entity into a temporary table in order to do a bulk update operation from an in-memory collection. When attempting to populate the temporary table with an entity of the same type that exists and matches by Id
in the main table, the temp table that is returned contains the entity as it exists in the main table, not the version of the entity that was supposed to be inserted into the temporary table.
The following test demonstrates the issue and fails on the current version of Linq2db/linq2db.EntityFrameworkCore:
[Fact]
public void BulkCopy_Inserts_Correctly_When_Id_Exists_In_Permanent_Table_With_Same_Model_Type()
{
var factory = new EFCoreSqliteInMemoryDbFactory();
var context = factory.CreateDbContext<MainContext>();
var person = new Person
{
Name = "John Doe"
};
context.Add(person);
context.SaveChanges();
var personCopy = new Person
{
Id = person.Id,
Version = BitConverter.GetBytes(1),
Name = "Jane Doe"
};
var connection = context.CreateLinqToDbConnection();
var transaction = connection.BeginTransaction();
var tempTable = connection.CreateTempTable(new List<Person> {personCopy},
new BulkCopyOptions {KeepIdentity = true}, "PersonUpdate");
transaction.Commit();
var firstPerson = tempTable.First();
firstPerson.Name.Should().Be(personCopy.Name);
firstPerson.Version.Should().BeEquivalentTo(personCopy.Version, options => options.WithStrictOrdering());
}
A demo repo reproducing the issue can be found here.
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (11 by maintainers)
Top Results From Across the Web
When to Use SQL Temp Tables vs. Table Variables
In this short blog post, we are going to provide you a short overview when to use SQL Temp Tables in place of...
Read more >How insert into a permanent table? - sql
I have this, but with a temporary table. How can I insert in a permanent table and then return it? SET ANSI_NULLS ON...
Read more >Temporary Tables In SQL Server
Temporary tables are very similar to permanent tables. Permanent tables get created in the database you specify and remain in the database ...
Read more >How to create a temporary table using VALUES in ...
You can define the types by casting the values of the first row: CREATE TEMP TABLE lookup (key, val) AS VALUES (0::bigint, -99999::int),...
Read more >Temporary Tables in SQL Server - Simple Talk
Temporary tables are used by every DB developer, but they're not likely to ... Next, Create a procedure to receive data for the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I do not forgot about this issue. Debugging, something weird, really.
Well, will look at this tomorrow. Too late here.