NHibernate 显式流畅列映射

发布于 2024-08-14 16:51:18 字数 758 浏览 5 评论 0原文

我有一组流畅的对象映射,如下所示:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

意中人 2024-08-21 16:51:18

用户/特殊用户的 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.

水晶透心 2024-08-21 16:51:18

假设 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文