首页 文章

如何使用Nhibernate将主键添加到组件表?

提问于
浏览
0

我有一个使用Fluent Nhibernate配置的Nhibernate应用程序 .

应用程序启动时使用SchemaUpdate自动生成数据库模式 .

该模型具有组件,此组件在数据库上创建为没有主键的表 .

需要使用MS SQL Server事务复制来复制数据库,这需要所有表上的主键 .

有没有办法让架构更新工具将主键应用于这些表?

问候

1 回答

  • 0

    nhibernate中的组件通常是引用对象的完全包含的对象

    以下是Fluent-Nhibernate Mapping Documentation - ComponentMap<T>

    public class Address
    {
      public int Number { get; set; }
      public string Street { get; set; }
      public string City { get; set; }
      public string PostCode { get; set; }
    }
    
    public class Person
    {
      public int Id { get; set; }
      public Address Address { get; set; }
    }
    
    public PersonMap()
    {
      Id( x => x.Id );
      Component(x => x.Address, m =>
      {
        m.Map(x => x.Number);
        m.Map(x => x.Street);
        m.Map(x => x.City);
        m.Map(x => x.PostCode);
      });
    }
    

    数据库应该是

    表:人

    • 同上

    • 数量

    • 城市

    • PostCode

    链接:

相关问题