NHibernate - 父表中的 KeyColumn
我的应用程序具有以下数据库结构:
Transactions:
- TransactionID (PK, Identity)
- Type
- TotalAmount
TransactionDetails:
- TransactionDetailID (PK, Identity)
- TransactionID (PK)
- Amount
ProductTransactions:
- TransactionID (PK, FK)
- Discount
ProductTransactionDetails:
- TransactionDetailID (PK, FK)
- ProductID (FK)
我使用 Fluent NHibernate 进行了映射,以便 ProductTransaction 继承自 Transaction 并使用 SubclassMap。我对 ProductTransactionDetail 和 TransactionDetail 做了同样的事情。我还有一个名为“Details”的属性,它是我的 Transaction 实体上的 TransactionDetail 列表,具有以下映射:
HasMany(x => x.Details)
.KeyColumn("TransactionID")
.Inverse()
.Cascade.All();
我希望能够在我的 ProductTransaction 实体上覆盖它。当使用 virtual 并覆盖时,编译器会抱怨,但新的 virtual 似乎可以工作。我遇到的问题是如何映射它,因为 ProductTransactionDetails 表中没有 TransactionID 列。它需要以某种方式从父表中获取它,但我不知道如何做到这一点。
如果有人可以帮助解决我遇到的问题,或者让我知道我是否以错误的方式处理事情,我将不胜感激。
谢谢
my application has the following database structure:
Transactions:
- TransactionID (PK, Identity)
- Type
- TotalAmount
TransactionDetails:
- TransactionDetailID (PK, Identity)
- TransactionID (PK)
- Amount
ProductTransactions:
- TransactionID (PK, FK)
- Discount
ProductTransactionDetails:
- TransactionDetailID (PK, FK)
- ProductID (FK)
I have this mapped using Fluent NHibernate so that ProductTransaction inherits from Transaction and uses a SubclassMap. I did the same for ProductTransactionDetail and TransactionDetail. I also have a property called "Details" which is a list of TransactionDetail on my Transaction entity with the following mapping:
HasMany(x => x.Details)
.KeyColumn("TransactionID")
.Inverse()
.Cascade.All();
I'd like to be able to override this on my ProductTransaction entity. When using virtual and override the compiler complained but new virtual seemed to work. The problem i have is how i map this since the ProductTransactionDetails doesn't have the TransactionID column in the table. It needs to somehow grab it from the parent table but i'm not sure how to do this.
I'd appreciate it if someone could help fix the issue i'm having or let me know if i'm going about things in the wrong way.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
注释在代码中...
领域模型
流畅映射
单元测试
Comments are in the code...
Domain Model
Fluent Mapping
Unit Tests