操作方法:从同一个表映射(NHibernate)具有不同业务逻辑的多个类?

发布于 2024-11-04 05:44:24 字数 507 浏览 0 评论 0原文

我目前正在使用一个棕地数据库,其中包含一个表,其中包含 3 种不同业务的数据。它与销售订单和订单行有关。在旧应用程序中,我们能够向每个销售订单添加 3 种类型的订单行:产品、小时费率和文本行。 15 年前,这是一种快速但肮脏的解决方案,可以在 Delphi 中进行简单查询以获取一个数据网格中的所有行。现在

我尝试使用 NHibernate 在 C# 中构建对象模型。我创建了 3 个没有基类的独立实体,因为这 3 个线类型没有真正的业务逻辑连接。但是,我想将这 3 种类型放入一个列表中,以便我可以订购它们。

我考虑过使用继承,每个类一个表,因为表满足要求(没有具有非空约束的列)。但这不是一个合乎逻辑的步骤,因为每种类型的业务完全不同(唯一的共同点是 userId、描述和备注)。也许是一个组件?但是如何将属性映射到 3 个不同的类,而无需基类或除表名之外的任何类型的链接?

我希望你们能理解我写的东西。我还没有真正的代码,我只是在纸上画了一些关于如何处理这些代码的内容。

这里有人可以帮助我吗?

亲切的问候, 特德

I am currently working with a brownfield database which contains a table which holds data for 3 different sorts of business. It has to do with SalesOrders and orderlines. In the old application, we were able to add 3 types of orderlines to each salesorder: products, hourly rates and text lines. 15 years ago, this was a quick and dirty solution to get easy queries in Delphi to get all the lines in one datagrid. Every

Now I am trying to build the object model in C# using NHibernate. I've made 3 seperate entities without a base class, due to the fact that these 3 line types have no real business logical connection. However, I want to get these 3 types into one list so I can order them.

I've considered using inheritence, table per class, as the table meets the requirements (no columns with a not-null restraint). This isn't a logical step though, since the business per type is completely different (only things in common are userId, description and remarks). Perhaps a component? but how to map the properties to 3 different classes without a base class or any kind of link except the table name?

I hope you guys understood what I wrote. I have no real code yet, I was just sketching some stuff on paper on how to deal with this code.

Anyone here who can help me on my way?

Kind regards,
Ted

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

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

发布评论

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

评论(1

谜泪 2024-11-11 05:44:24

您可以在三个实体上放置一个接口并将其映射为基类,全部

interface IWhatever 
{
  // central Id for the whole table
  int Id { get; set; }
  // may be some more properties
}

class Product : IWhatever
{
  // ...
}

class HourlyRate : IWhatever
{
  // ...
}

class TextLines : IWhatever
{
  // ...
}

映射到同一个表:

<class name="IWhatever" table="MyBigTable">

  <id .../>
  <discriminator column="Type"/>
  <subclass name="Product" discriminator-value="P">
    <!-- ... -->
  </subclass>
  <subclass name="HourlyRate" discriminator-value="HR">
    <!-- ... -->
  </subclass>
  <subclass name="TextLines" discriminator-value="TL">
    <!-- ... -->
  </subclass>
</class>

You could put an interface on the three entities and map it as a base class, all to the same table:

interface IWhatever 
{
  // central Id for the whole table
  int Id { get; set; }
  // may be some more properties
}

class Product : IWhatever
{
  // ...
}

class HourlyRate : IWhatever
{
  // ...
}

class TextLines : IWhatever
{
  // ...
}

Mapping:

<class name="IWhatever" table="MyBigTable">

  <id .../>
  <discriminator column="Type"/>
  <subclass name="Product" discriminator-value="P">
    <!-- ... -->
  </subclass>
  <subclass name="HourlyRate" discriminator-value="HR">
    <!-- ... -->
  </subclass>
  <subclass name="TextLines" discriminator-value="TL">
    <!-- ... -->
  </subclass>
</class>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文