NHibernate/FluentNHibernate property bag

前端 未结 3 1916
栀梦
栀梦 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:01

    I agree entirely with Stefan's points, and although I can't attest to the correctness of his mapping, the literal translation into Fluent NHibernate is as follows:

    public class VehicleMap : ClassMap
    {
      public VehicleMap()
      {
        Id(x => x.Id);
        Map(x => x.Registration);
    
        HasMany(x => x.Properties)
          .Component(c =>
          {
            c.Map(x => x.Name);
            c.Map(x => x.Value);
          })
          .Cascade.AllDeleteOrphan();
      }
    }
    

提交回复
热议问题