linq2db.EntityFrameworkCore: CreateTempTable returning entity in permanent table
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!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 24 (11 by maintainers)
I do not forgot about this issue. Debugging, something weird, really.
Well, will look at this tomorrow. Too late here.
Well, not found time to look at. Moving to tomorrow.