NHibernate/FluentNHibernate property bag

前端 未结 3 1886
栀梦
栀梦 2021-01-13 22:44

Given a Vehicle class and a VehicleProperty class...

public class Vehicle
{
    public virtual int Id { get; protected set; }
    public virtual string Regis         


        
3条回答
  •  借酒劲吻你
    2021-01-13 23:10

    1. Don't use composite id's.
    2. Inverse means, that this is the inverse relation of an other one. If there is no other one, it's just not updated.
    3. You declared the VehicleProperty.Name Property as the primary key. if the primary key is already initialized, NH thinks it is already stored and therefore tries an update. (that's why you get the exception.) You can changed this behaviour, but it's better to use an artificial primary key or the mapping bellow.

    I don't know FluentNHibernate to show you the code. I can tell you how it looks in XML.

    
      
    
      
    
      
      
    
        
        
    
        
        
          
          
        
      
    
    
    

提交回复
热议问题