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

后端 未结 3 2087
生来不讨喜
生来不讨喜 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:01

    You are trying to map a one-to-one relationship as a one-to-many by mapping what would be the many side twice. That won't work. NHibernate is strict in its definition of one-to-one and requires that both sides have the same primary key, so that won't work either.

    I've butted heads with this before and the best workaround I found is to model it as a standard on-to-many but only allow one item in the collection by encapsulating access to the it. In your case I would guess that Product would be the one side and Config the many.

提交回复
热议问题