nhibernate 使用奇怪的别名生成不正确的 sql 查询
所以我有一个名为 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Groups 属性的别名中有一个空格。
.CreateAlias("a.Groups", "ag")
There is a space in your alias of the Groups property.
.CreateAlias("a.Groups", " ag")