question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CreateTempTable returning entity in permanent table

See original GitHub issue

Hi,

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:closed
  • Created 2 years ago
  • Comments:24 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Jul 14, 2021

I do not forgot about this issue. Debugging, something weird, really.

1reaction
sdanylivcommented, Jul 8, 2021

Well, will look at this tomorrow. Too late here.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found