nhibernate - NHibernate QueryOver 并选择属性为 ILIST 且列表计数 >= 1 的行
问题描述
我想选择属性 ItemsIList
本身具有行的行。在 SQL 中,它的简单计数 >= 1 但在 NHibernate 中它让我望而却步。
尝试了很多方法
public class Sale
{
private IList<Items> _items;
public Sale()
{
_items = new List<Item>();
}
public Guid SaleId { get; set; }
public string SaleNumber { get; set; }
public string Location { get; set; }
public DateTime? SaleDateTime { get; set; }
public IList<Item> Items => _items;
}
public class Item
{
public Guid ItemId { get; set; }
public string description { get; set; }
}
var testdata = _session.QueryOver<Sale>()
.Where(Restrictions.Ge(
Projections.Property<Sale>
(m => m.Items.Count), 1))
.ReadOnly()
.ListAsync();
Count
无法识别
解决方案
从技术上讲,如果您进行了内部联接,您将不会收到任何Sale
没有任何记录的Item
记录。
因此,QueryOver
您可以非常简单地执行以下操作:
var sales = session.QueryOver<Sale>()
.Inner.JoinQueryOver(x => x.Items)
.Select(Projections.RootEntity())
.TransformUsing(Transformers.DistinctRootEntity)
.List();
这是生成的 SQL:
SELECT this_.SaleId as saleid1_1_0_,
this_.SaleNumber as salenumber2_1_0_,
this_.Location as location3_1_0_,
this_.SaleDateTime as saledatetime4_1_0_
FROM Sale this_
inner join Item item1_ on this_.SaleId=item1_.SaleId
推荐阅读
- node.js - 如何在对话流实现中使用 OR 运算符
- kubernetes - redis/postgres 卷声明和应用程序配置之间的关系
- javascript - 如何在不询问位置的情况下工作天气
- c - 知道 Linux 如何确定应该在内核模块中打印哪个字符串吗?
- android - 如何在android中创建一个盒子阴影?
- delphi - 使用 Delphi XE 从 FTP 服务器下载目录
- visual-studio-code - 如何在代理后面打包 VS Code Extension
- c++ - 在 Lua C API 中使用自定义函数编辑内存
- jquery - 总是在按钮单击时返回 Post 400 Error jQuery
- php - 从 Internet 访问 ZeroTier 网络 - 连接被拒绝