Fluent NHibernate Generated AND Assigned ID Columns

后端 未结 2 1439
情深已故
情深已故 2020-12-16 15:42

I\'m using Fluent NHibernate for my data-persistence in a web application.

My problem... I have a base class that maps all entities with an ID property of type T (al

相关标签:
2条回答
  • 2020-12-16 16:29

    you can use

    Id(I => I.Id).GeneratedBy.Increment(); //Increment by 1
    
    0 讨论(0)
  • 2020-12-16 16:33
    Id(x => x.Id).GeneratedBy.Assigned();
    

    If you want the application to assign identifiers (as opposed to having NHibernate generate them), you may use the assigned generator. This special generator will use the identifier value already assigned to the object's identifier property. Be very careful when using this feature to assign keys with business meaning (almost always a terrible design decision).

    Due to its inherent nature, entities that use this generator cannot be saved via the ISession's SaveOrUpdate() method. Instead you have to explicitly specify to NHibernate if the object should be saved or updated by calling either the Save() or Update() method of the ISession.

    http://nhibernate.info/doc/nhibernate-reference/mapping.html#mapping-declaration-id-assigned

    0 讨论(0)
提交回复
热议问题