NHibernate 显式流畅列映射
我有一组流畅的对象映射,如下所示:
public class UserMap : ClassMap<User>
{
public UserMap()
{
Map(x => x.Id);
Map(x => x.Status);
}
}
public class SpecialUserMap : SubClassMap<SpecialUser>
{
public SpecialUserMap()
{
Map(x => x.Property);
}
}
public class DirectoryMap : ClassMap<Directory>
{
public DirectoryMap
{
Map(x => x.Id);
HasMany(x => x.SpecialUsers).Where("Status = 0");
}
}
User 是一个联接表,SpecialUser 联接该表以获取状态等信息。但是,当我尝试引用 Directory 的 SpecialUsers 集合中的 SpecialUser 时,出现“未定义列 'Status'” 的错误,就像在生成的 SQL 中一样,NHibernate 尝试从 SpecialUser 表而不是 User 表中获取 Status 列。 有没有办法明确告诉 NHibernate 哪个表获取 DirectoryMapping 中的 Status 列?
I have a set of fluent object mappings that looks like this:
public class UserMap : ClassMap<User>
{
public UserMap()
{
Map(x => x.Id);
Map(x => x.Status);
}
}
public class SpecialUserMap : SubClassMap<SpecialUser>
{
public SpecialUserMap()
{
Map(x => x.Property);
}
}
public class DirectoryMap : ClassMap<Directory>
{
public DirectoryMap
{
Map(x => x.Id);
HasMany(x => x.SpecialUsers).Where("Status = 0");
}
}
User is a join table, which SpecialUser joins against to get things like status. However, when I try to reference a SpecialUser in Directory's SpecialUsers collection, I get an error of "Undefined column 'Status'", as in the generated SQL, NHibernate tries to grab the Status column from the SpecialUser table, and not the User table.
Is there a way to explicitly tell NHibernate which table to get the Status column in the DirectoryMapping?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用户/特殊用户的 Status 属性需要映射到数据库中的单个列。您不能让它有时来自 User,有时来自 SpecialUser。
作为解决方法,您可以将 SpecialUserStatus 属性添加到 SpecialUser,然后您可以轻松查询。
The Status property of a User / SpecialUser needs to map onto a single column in the database. You can't have it coming sometimes from User and sometimes from SpecialUser.
As a workaround, you could add a SpecialUserStatus property to SpecialUser, and then you could query on that easily.
假设 SpecialUser 扩展了 User,该映射看起来适合 table-per-subclass 映射。我的猜测是这是一个错误。
That mappings looks right for table-per-subclass mapping, assuming that SpecialUser extends User. My guess is that it's a bug.