mapping nhibernate parent/child relationship the 'other' way round

后端 未结 3 2052
生来不讨喜
生来不讨喜 2021-01-22 10:50

using FluentNhibernate;

I am trying to persist a seemingly simple object model:

public class Product
{
    public int Id { get; set; }
    public string          


        
3条回答
  •  太阳男子
    2021-01-22 11:02

    I'm not sure if Config is used elsewhere but you could ignore ConfigId as its identity

    public class Config
    {
        public int Id { get; set; }
        public Product Product { get; set; }
        public string ConfigField1 { get; set; }
        public string ConfigField2 { get; set; }
    }
    
    public class ProductMap : ClassMap
    {
        public class ProductMap()
        {
            HasOne(p => p.Config);
        }
    }
    
    public class ConfigMap : ClassMap
    {
        public class ConfigMap()
        {
            Id(c => c.Id, "ProductId").GeneratedBy.Foreign("Product");
    
            References(c => c.Product, "ProductId");
            Map(c => ...);
        }
    }
    

提交回复
热议问题