nhibernate not saving foreign key Id

前端 未结 5 788
没有蜡笔的小新
没有蜡笔的小新 2021-02-04 19:26

I have a simple model I\'m attempting to persist using fluent-nhibernate:

public class Person
{
    public int Id { get; set; }
    public string Name { get; set         


        
5条回答
  •  心在旅途
    2021-02-04 19:58

    Seems to be a design issue

    If the intent is to avoid reference of person within address on a/c of contextual use of the address

    Then i would introduce a "discriminator"

    i.e.

    Address {AddressId, ...}
    PersonAddress : Address {Person, ...}, 
    CustomerAddress : Address {Customer, ...}, 
    VendorAddress : Address {Vendor, ...}
    

    You could infer the discriminator via formula as well rather specifying a hard discriminator value

    Ref : Discriminator based on joined property

    Alternatively modify the db structure if allowed / possible

    Persons [PersonId, ...]
    Addresses [AddressId]
    AddressDetails [AddressDetailId, AddressId, ...]
    

    With Mappings as follows (no idea how this would be done in fluent, but is possible via xml) 1.) Person + Addresses via a join table 2.) Address + AddressDetails via reference

    I would definitely prefer the first option

    cheers ...

提交回复
热议问题