在连接列上使用 Fluent Nhibernate ApplyFilter

发布于 2024-10-22 16:39:01 字数 1111 浏览 2 评论 0原文

我正在尝试在从另一个表连接(和投影)的列上应用过滤器(ApplyFilter)。我有以下实体:

public class User
{
    public virtual int Id { get; private set; }
    public virtual string EMail { get; set; }
    ...
    public virtual bool IsActive { get; set; }
    public virtual int CompanyId { get; set; }
}

使用 UserMap:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("Users");
        Id(x => x.Id, "UserId");
        Map(x => x.EMail);
        ...

        Join("CompanyUser", r =>
        {
            r.KeyColumn("UserId");
            r.Map(x => x.IsActive);
            r.Map(x => x.CompanyId);
            r.Fetch.Join();

        });

        ApplyFilter<CompanyFilter>("this_1_.CompanyId = :companyId");
    }

这实际上现在可以工作,但正如您所看到的,我必须在过滤器中包含 CompanyUser 表的别名“this_1_”...这听起来不正确,但是如果我保留 FilterDefinition 类中定义的过滤器,我会得到一个带有 a: 的 Sql

where this.CompanyId = ?p0

,它没有映射,因为 CompanyId 列来自不同的投影(CompanyUser as this_1_)

有没有办法纠正这个问题并让 nhibernate 计算过滤器的正确别名?

预先感谢您的任何帮助。

I'm trying to apply a filter (ApplyFilter) on a column that is Join (and projected) from another table. I have the following entity:

public class User
{
    public virtual int Id { get; private set; }
    public virtual string EMail { get; set; }
    ...
    public virtual bool IsActive { get; set; }
    public virtual int CompanyId { get; set; }
}

With a UserMap:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("Users");
        Id(x => x.Id, "UserId");
        Map(x => x.EMail);
        ...

        Join("CompanyUser", r =>
        {
            r.KeyColumn("UserId");
            r.Map(x => x.IsActive);
            r.Map(x => x.CompanyId);
            r.Fetch.Join();

        });

        ApplyFilter<CompanyFilter>("this_1_.CompanyId = :companyId");
    }

This actually works right now, but as you can see I'm having to include the alias name "this_1_" for the CompanyUser table in the filter... this doesn't sound correct, but if I leave the filter as is defined in the FilterDefinition class I get a Sql with a:

where this.CompanyId = ?p0

which is not mapped 'cos the CompanyId column comes from a different projection (CompanyUser as this_1_)

Is there a way to correct this and let nhibernate figure out the correct alias for the filter?

Thanks in advance for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

帅冕 2024-10-29 16:39:01

我认为你必须在连接上应用过滤器:

    Join("CompanyUser", r =>
    {
        r.KeyColumn("UserId");
        r.Map(x => x.IsActive);
        r.Map(x => x.CompanyId);
        r.Fetch.Join();

    }).ApplyFilter<CompanyFilter>("CompanyId = :companyId");

I think you must apply the filter on the join:

    Join("CompanyUser", r =>
    {
        r.KeyColumn("UserId");
        r.Map(x => x.IsActive);
        r.Map(x => x.CompanyId);
        r.Fetch.Join();

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