NHibernate / Fluent NHibernate 映射

发布于 2024-09-18 14:09:39 字数 191 浏览 13 评论 0原文

是否可以绘制以下情况?

  1. 产品类(当前是一个表)
  2. 一个帐户类(当前是一个表)
  3. 一个帐户产品类(当前是一个联接表,但具有与特定产品和帐户相关的附加信息)

我理想中想要的是帐户产品来扩展产品并成为可作为财产产品从帐户中获取。

产品类将单独存在并提供其自己的持久性。

Is it possible to map the following situation?

  1. A product class (currently a table)
  2. An account class (currently a table)
  3. An accountproduct class (currently a join table but with additional information related to a specific product and account)

What I'd ideally like is accountproduct to extend product and to be available from account as a property Products.

The product class would exist seperately and provide it's own peristance.

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

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

发布评论

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

评论(1

一绘本一梦想 2024-09-25 14:09:39

怎么样:

    public class AccountProduct
    {
        public virtual int Id { get; set; }
        public virtual DateTime Date { get; set; }
        public virtual string Comments { get; set; }

        public virtual Account Account { get; set; }
        public virtual Product Product { get; set; }

        public class AccountProductMap : ClassMap<AccountProduct>
        {
            public AccountProductMap()
            {
                Id(x => x.Id);
                Map(x => x.Date);
                Map(x => x.Comments);
                References(x => x.Account);
                References(x => x.Product);
            }
        }
    } 

    public class Product
    {
        public virtual int Id { get; set; }
        public virtual int Name { get; set; }

        public class ProductMap : ClassMap<Product>
        {
            public ProductMap()
            {
                Id(x => x.Id);
                Map(x => x.Name);
            }
        }
    }

    public class Account
    {
        public virtual int Id { get; set; }
        public virtual int Name { get; set; }

        public class AccountMap : ClassMap<Account>
        {
            public AccountMap()
            {
                Id(x => x.Id);
                Map(x => x.Name);
            }
        }
    }

How about the following:

    public class AccountProduct
    {
        public virtual int Id { get; set; }
        public virtual DateTime Date { get; set; }
        public virtual string Comments { get; set; }

        public virtual Account Account { get; set; }
        public virtual Product Product { get; set; }

        public class AccountProductMap : ClassMap<AccountProduct>
        {
            public AccountProductMap()
            {
                Id(x => x.Id);
                Map(x => x.Date);
                Map(x => x.Comments);
                References(x => x.Account);
                References(x => x.Product);
            }
        }
    } 

    public class Product
    {
        public virtual int Id { get; set; }
        public virtual int Name { get; set; }

        public class ProductMap : ClassMap<Product>
        {
            public ProductMap()
            {
                Id(x => x.Id);
                Map(x => x.Name);
            }
        }
    }

    public class Account
    {
        public virtual int Id { get; set; }
        public virtual int Name { get; set; }

        public class AccountMap : ClassMap<Account>
        {
            public AccountMap()
            {
                Id(x => x.Id);
                Map(x => x.Name);
            }
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文