【问题标题】:fluent nhibernate many to many convention automapping流利的休眠多对多约定自动映射
【发布时间】:2012-10-31 15:12:48
【问题描述】:

我正在使用具有自动映射和约定的 FluentNH。我这样设置了多对多约定:

    public class HasManyToManyConvention : IHasManyToManyConvention
    {
        public void Apply(IManyToManyCollectionInstance instance)
        {
            instance.Key.Column(instance.EntityType.Name + "Id");
            instance.Relationship.Column(instance.Relationship.StringIdentifierForModel + "Id");
        }
    } 

假设这些是我的表: 用户(ID,用户名,密码), 角色(ID,姓名)

在数据库生成时,关联表正在生成正常: UserInRole(UserId,RoleId)

但是,它没有复合主键集。知道如何从公约中解决这个问题吗?

有人吗?可能是目前 Fluent 不支持此功能?

【问题讨论】:

  • instance.Relationship.Column() 的每次调用都会在instance.Relation.Columns 集合中的现有列中添加另一个,这样就解释了为什么要获得复合主键集。我目前正在研究一种重置列的方法,但到目前为止我运气不佳。
  • 请参考我的相关问题:stackoverflow.com/questions/9772230/…
  • @SandorDrieënhuizen 引用的帖子已被删除。

标签: fluent-nhibernate fluent-nhibernate-mapping


【解决方案1】:

原来约定应该保持不变。但是,我现在使用 ISet 和 ISet,而不是在我的实体定义中使用 IList 和 IList。现在 NHibernate 会自动在关联表上创建一个复合主键。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-07
    • 1970-01-01
    • 2023-03-14
    • 1970-01-01
    相关资源
    最近更新 更多