-
Notifications
You must be signed in to change notification settings - Fork 936
Closed
Description
We are having problems upgrading to new version 5.3.0 due to a breaking change on delay entity insert on persist: #1754
I read the discusson and agreed that Persist should delay entity insert, but Save does it immediatly.
Is it correct that Merge methos doesn't create identity immediatly?
I think that Merge method should work like Save.
For this reason, if I create a OneToOne relation between two objects with the same primary key:
- Merge gives "Specific cast is not valid"
- Save works correctly
Example:
public TableAMap()
{
Schema("[dbo]");
Table("TEST_TABLE_A");
Not.LazyLoad();
Id(x => x.Id).Column("ID");
Map(x => x.Name).Column("NAME").Length(100).Not.Nullable();
Map(x => x.Description).Column("DESCRIPTION").Length(1000).Nullable();
Map(x => x.CreationDate).Column("CREATION_DATE").Not.Nullable();
HasOne(x => x.TableB).Not.LazyLoad().Cascade.All();
}
public TableBMap()
{
Schema("[dbo]");
Table("TEST_TABLE_B");
Not.LazyLoad();
Id(x => x.Id).Column("ID").GeneratedBy.Foreign("TableA");
Map(x => x.Color).Column("COLOR").Length(100).Nullable();
HasOne(x => x.TableA).Constrained();
}
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var tableA = new TableA {Name = "test", Description = "it works?", CreationDate = DateTime.UtcNow};
tableA.TableB = new TableB { TableA = tableA, Color = "red" };
session.Save(tableA);
//session.Merge(tableA);
transaction.Commit();
var test = session.Query<TableA>().FirstOrDefault(x => x.Id == tableA.Id);
}
}