如何将现有表映射到 NHibernate 中的继承层次结构中?
问题是尝试在给定现有表结构的情况下映射继承。该表还被使用原始 SQL 的遗留应用程序使用,即该表无法删除任何现有架构详细信息,但可以添加更多内容。
现有的表已经被映射,并且本质上有一堆存在以下问题的字段......
现有类
class A
{
// Id etc
public virtual Client Client { get; set; }
}
所以具有像这样的表结构的
table A (
Id INT IDENTITY NOT NULL,
Client_id INT null,
primary key (Id)
)
现在我想引入一个基类
class Base
{
// Id etc
public virtual Client Client { get; set; }
}
,它最终会得到一个像......
table Base (
Id INT IDENTITY NOT NULL,
Client_id INT null,
primary key (Id)
)
这样的 表将 A 更改为
class A : Base
{
// clients moved to the base...
}
将对表执行类似的操作:-
table A(
Base_id INT IDENTITY NOT NULL,
Id INT not null, // I will need to keep the existing Id field...
Client_id INT null, // this Client now conflicts with the Base client
primary key (Base_id)
)
我正在使用每个类继承的表。
问题是...
“Client”将位于“Base”的表上,并且位于“A”的现有表上。我希望能够继续使用“A”上的“客户端”,作为一种覆盖。
我该怎么做?我可以这样做吗?
或者是否有可能在表“Base”上根本没有“Client”,然后在所有子类表上定义“Client”? (这会让查询变得有趣)
The problem is trying to map inheritance given an existing table structure. The table is also used by legacy apps using raw sql, ie, the table can't delete any existing schema details, but can add more to it.
The existing table is already mapped, and essentially has a bunch of fields with the following problem....
so existing class
class A
{
// Id etc
public virtual Client Client { get; set; }
}
with a table structure like
table A (
Id INT IDENTITY NOT NULL,
Client_id INT null,
primary key (Id)
)
Now I want to introduce a base class
class Base
{
// Id etc
public virtual Client Client { get; set; }
}
which will end up with a table like...
table Base (
Id INT IDENTITY NOT NULL,
Client_id INT null,
primary key (Id)
)
and change A to
class A : Base
{
// clients moved to the base...
}
which will do something like this to the table :-
table A(
Base_id INT IDENTITY NOT NULL,
Id INT not null, // I will need to keep the existing Id field...
Client_id INT null, // this Client now conflicts with the Base client
primary key (Base_id)
)
I'm using table per class inheritance.
the problem is....
'Client' will be on the table of "Base" and also it's on the existing table of "A". I want to be able to keep using the 'Client' on "A", as a kind of override.
How do I do this? can I do this?
or is it possible that on table "Base" it doesn't have 'Client' at all and then on all the subclass tables they define "Client"? (which would make querying interesting)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果只是查询NH应该支持接口查询
if its only for querying NH should support Querying by interface