实体上与 nhibernate 的多对多关系

发布于 2024-10-10 09:40:52 字数 695 浏览 3 评论 0原文

我有一个 nhibernate 问题,

我有一个包含多对多关系的 hbm 文件。 到目前为止,这是有效的,但我想从实体生成 hbm

并尝试在实体上设置属性,但这不会编译

这是 hbm 文件

<list name="Category" table="Category" lazy="false" fetch="select" cascade="none">
  <key column="categoryId" />
  <index column="ordinal" />
  <many-to-many class="Product, Assembly" column="productId" />
</list>

,现在已在实体上执行此操作

    [List(2, Name = "Product", Table = "Product", Cascade = CascadeStyle.None, Lazy = false, Fetch = CollectionFetchMode.Select)]
    [ManyToMany(5, ClassType = typeof(Product), Column = "productId")]
    public virtual IList<Category> Categorys

I have a problem with nhibernate,

i have a hbm file with a many to many relations.
This works so far but i want to generate the hbm from a entity

and trying to set the properties on the entity but that will not compile

this is the hbm file

<list name="Category" table="Category" lazy="false" fetch="select" cascade="none">
  <key column="categoryId" />
  <index column="ordinal" />
  <many-to-many class="Product, Assembly" column="productId" />
</list>

and have did now on the entity

    [List(2, Name = "Product", Table = "Product", Cascade = CascadeStyle.None, Lazy = false, Fetch = CollectionFetchMode.Select)]
    [ManyToMany(5, ClassType = typeof(Product), Column = "productId")]
    public virtual IList<Category> Categorys

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2024-10-17 09:40:52

您忘记了实体上的序号和键
试试这个

    [List(1, Name = "Product", Table = "Product", Cascade = CascadeStyle.None, Lazy = false, Fetch = CollectionFetchMode.Select)]
    [NHibernate.Mapping.Attributes.Key(2, Column = "categoryId")]
    [Index(3, Column = "ordinal")]
    [ManyToMany(4, ClassType = typeof(Product), Column = "productId")]
    public virtual IList<Category> Categorys

You forgot the ordinal and the key on the entity
try this

    [List(1, Name = "Product", Table = "Product", Cascade = CascadeStyle.None, Lazy = false, Fetch = CollectionFetchMode.Select)]
    [NHibernate.Mapping.Attributes.Key(2, Column = "categoryId")]
    [Index(3, Column = "ordinal")]
    [ManyToMany(4, ClassType = typeof(Product), Column = "productId")]
    public virtual IList<Category> Categorys
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文