If I use a session per transaction and call:
session.SaveOrUpdate (entity) fixed:
session.SaveOrUpdateCopy (entity)
.. and the entity is a temporary instance with identifier-Id = 0. Should the next line automatically update the identifier of the object and make the instance permanent? Or he should do it on a transaction. Commit? Or do I need to explicitly state this somehow?
Obviously, the database row identifier (new, as a transitional one) is autogenerated and stored as some number, but I'm talking about the actual instance of the parameter here. What an instance of business logic.
EDIT - Follow-up work related to this issue.
Display:
public class StoreMap : ClassMap<Store> { public StoreMap() { Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Name); HasMany(x => x.Staff) // 1:m .Cascade.All(); HasManyToMany(x => x.Products) // m:m .Cascade.All() .Table("StoreProduct"); } } public class EmployeeMap : ClassMap<Employee> { public EmployeeMap() { Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.FirstName); Map(x => x.LastName); References(x => x.Store); // m:1 } } public class ProductMap : ClassMap<Product> { public ProductMap() { Id(x => x.Id).GeneratedBy.Identity(); Map(x => x.Name).Length(20); Map(x => x.Price).CustomSqlType("decimal").Precision(9).Scale(2); HasManyToMany(x => x.StoresStockedIn) .Cascade.All() .Inverse() .Table("StoreProduct"); } }
EDIT2
Class Definitions:
public class Store { public int Id { get; private set; } public string Name { get; set; } public IList<Product> Products { get; set; } public IList<Employee> Staff { get; set; } public Store() { Products = new List<Product>(); Staff = new List<Employee>(); }
source share