ActiveRecord/NHibernate 中多个类可以共享单个数据库表吗
C# w/Castle ActiveRecord
我在 C# 中有两个(或更多)类,我想与同一个数据库表进行交互。这两个类不共享基类,因此我无法使用鉴别器。我只想将表列划分为两个(或更多)类。这与 JoinedTable 属性的目的相反。这可以做到吗?
C# w/Castle ActiveRecord
I've two (or more) classes in C# that I'd like to interact with the same database table. These two classes do NOT share a base class, so I can't use a Discriminator. I'd simply like to divide the table columns over two (or more) classes. Kind of the opposite of the purpose of the JoinedTable attribute. Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了扩展我的评论,您可以通过继承多个接口对活动记录对象中的列进行逻辑分组......
To expand on my comment, you can logically group the columns in the active record object by inheriting multiple interfaces...
有两种策略可以将多个类映射到一张表:
继承:是的,我知道你没有它,但你也可以使用接口作为“基类”。在同一个表中拥有多个没有任何共同点的(根)类是没有意义的。
组件:与连接实际上相反。您可以将表的某些部分放入单独的类中。在这种情况下,只有一个根实体聚合其他类。
There are two strategies to map several classes to one table:
Inheritance: yes, I know you don't have it, but you could also use an interface as "base class". It doesn't make sense to have several (root) classes in the same table witch don't have anything in common.
Components: are the actual opposite of join. You can put parts of the table to separate classes. In this case, there is only one root entity which aggregates other classes.