在 FluentNHibernate 中指定 HasMany() 关系映射上的表
我在 FluentNHibernate 中有一个 HasMany 关系的映射,我想在其上指定一个表来覆盖 nHibernate 将查找的默认表以查找我拥有的许多对象。这有道理吗?
假设我有一个发票表和一个 InvoiceItems 表,并且假设我有一个名为 InvoiceItemsTwo 的表。
我有一个 Invoice 类和一个 InvoiceItems 类,它们的映射非常简单。我想在 Invoice 的映射中指定它应该在 InvoiceItemsTwo 而不是默认的 InvoiceItems 中查找它的项目。
所以我对这种关系的映射看起来像这样
HasMany(c => c.InvoiceItems).Cascade.SaveUpdate().Table("InvoiceItemsTwo");
但这不起作用。我在运行时不断从我的网站收到错误,提示对象名称“InvoiceItems”无效。
为什么它忽略了我在关系映射中显式指定表的事实?
我尝试在运行时转储映射,并且正在设置类似这样的内容
<bag cascade="save-update" table="InvoiceItemsTwo">
有什么想法吗?
I have a mapping in FluentNHibernate for a HasMany relationship and I'd like to specify a Table on it to override the default Table that nHibernate will look in to find those objects that I have many of. Does that make sense?
So lets say I have a table for Invoices and a table for InvoiceItems and lets say I have table called InvoiceItemsTwo.
I have a class for Invoice and a Class for InvoiceItems as well, and their mappings are pretty straight forward. I'd like to specify in my mapping for Invoice, that it should look for it's items in InvoiceItemsTwo instead of the default InvoiceItems.
So my mapping of that relationship looks like this
HasMany(c => c.InvoiceItems).Cascade.SaveUpdate().Table("InvoiceItemsTwo");
But this doesn't work. I keep getting an error from my website at runtime that says Invalid object name 'InvoiceItems'.
Why is it ignoring the fact that I am explicitly specifying the Table in my mapping on the relationship?
I tried dumping the mapping at run time and it's being setup something like this
<bag cascade="save-update" table="InvoiceItemsTwo">
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
table
属性仅适用于多对多关系,不适用于一对多关系。The
table
attribute applies only to many-to-many relationships, not one-to-many.您不能在映射类中指定不同的表。 Fluent NHibernate 使用映射到属性列表 (InvoiceItems) 上的类。
如果您想使用另一个类来映射您的详细信息表,您必须创建一个 InvoceItemsTwo 类并将其映射到您的主表类中。
you can't specify a different table in your mapping class. Fluent NHibernate uses the class mapped on the property list (InvoiceItems).
If yoy want to use another class to map your details table you must create a InvoceItemsTwo class and map it in your master table class.
您可以将列表映射为复合元素而不是一对多关系,然后将其映射到另一个表。但这不是一个好主意。考虑一下 NH 需要知道在内存中存储对象的位置。所以可能会出现对象存储在错误的表中的情况。
You could map the list as composite-element instead of a one-to-many relation and then map it to another table. But it is not a good idea. Consider that NH needs to know where to store an object which is in memory. So it may happen that the object is stored in the wrong table.