nhibernate not saving foreign key Id

前端 未结 5 791
没有蜡笔的小新
没有蜡笔的小新 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 20:10

    With a little tweak to your original code this can be achieved, for clarity I will post the entire code,

    public class Person
        {
            public virtual int Id { get; set; }
    
            public virtual string Name { get; set; }
    
            public virtual IList
    Addresses { get; set; } } public class Address { public virtual int Id { get; set; } public virtual int PersonId { get; set; } public virtual string Street { get; set; } } public class PersonOverrides : IAutoMappingOverride { public void Override(AutoMapping mapping) { mapping.Id(x => x.Id); mapping.HasMany(x => x.Addresses).KeyColumn("PersonId").Cascade.All(); } }

    Here is the changed code,

    public class AddressOverrides : IAutoMappingOverride
    { public void Override(AutoMapping
    mapping) { mapping.Id(x => x.Id); mapping.Map(x => x.PersonId).Column("PersonId"); } }

提交回复
热议问题