nhibernate 使用奇怪的别名生成不正确的 sql 查询

发布于 2025-01-05 22:57:42 字数 1258 浏览 3 评论 0原文

所以我有一个名为 VideoAsset 的实体,它映射到 VideoCategory 和 Group。两者都是多对多:

public class VideoAssetMap : IAutoMappingOverride<VideoAsset>
{

    public void Override(AutoMapping<VideoAsset> mapping)
    {
        mapping.Map(x => x.Description)
            .CustomSqlType("NTEXT");

        mapping.HasManyToMany<Group>(x => x.Groups)
            .Table("VideoAssetGroups")
            .ParentKeyColumn("VideoAssetId")
            .ChildKeyColumn("GroupId")
            .AsSet();

        mapping.HasManyToMany<VideoCategory>(x => x.Categories)
            .Table("VideoCategoryRel")
            .ParentKeyColumn("VideoCategoryId")
            .ChildKeyColumn("VideoAssetId")
            .AsSet();
    }

}

当我尝试使用以下命令在 nunit 和 sqlite 中运行以下查询时:

ICriteria query = this.Session.CreateCriteria<VideoAsset>("a")
            .CreateAlias("a.Categories", "c")
            .CreateAlias("a.Groups", " ag")
            .Add(Restrictions.Eq("c.Id", category.Id))
            .Add(Restrictions.Eq("a.Enabled", true));

我的 sql 无法执行,因为它已损坏:

inner join Groups alias_ ag2_ on groups4_.GroupId=alias_ ag2_.GroupId

我检查了我的数据库表,我不相信它们有任何问题。有什么想法吗?

So I have An entity called VideoAsset that is mapped to a VideoCategory and Group. Both are many to many:

public class VideoAssetMap : IAutoMappingOverride<VideoAsset>
{

    public void Override(AutoMapping<VideoAsset> mapping)
    {
        mapping.Map(x => x.Description)
            .CustomSqlType("NTEXT");

        mapping.HasManyToMany<Group>(x => x.Groups)
            .Table("VideoAssetGroups")
            .ParentKeyColumn("VideoAssetId")
            .ChildKeyColumn("GroupId")
            .AsSet();

        mapping.HasManyToMany<VideoCategory>(x => x.Categories)
            .Table("VideoCategoryRel")
            .ParentKeyColumn("VideoCategoryId")
            .ChildKeyColumn("VideoAssetId")
            .AsSet();
    }

}

When I try to run the following query in nunit with sqlite using the following:

ICriteria query = this.Session.CreateCriteria<VideoAsset>("a")
            .CreateAlias("a.Categories", "c")
            .CreateAlias("a.Groups", " ag")
            .Add(Restrictions.Eq("c.Id", category.Id))
            .Add(Restrictions.Eq("a.Enabled", true));

My sql can't execute because it's broken:

inner join Groups alias_ ag2_ on groups4_.GroupId=alias_ ag2_.GroupId

I checked my database tables and I don't believe there is anything wrong with them. Any Ideas?

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

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

发布评论

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

评论(1

自由如风 2025-01-12 22:57:42

Groups 属性的别名中有一个空格。

.CreateAlias("a.Groups", "ag")

There is a space in your alias of the Groups property.

.CreateAlias("a.Groups", " ag")

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