using SqlSugar; using System; using System.Collections.Generic; using System.Data.SqlTypes; using System.Linq; using System.Security.Principal; using System.Text; using System.Threading.Tasks; using System.Xml.Serialization; namespace OrmTest { internal class USelectDTO { public static void Init() { var db = NewUnitTest.Db; db.CodeFirst.InitTables(); //5.1.4.86 不报错 //5.1.4.94 报错 var flowQuery = db.Queryable() .GroupBy(s => new { s.ProductId }) .Select(s => new { s.ProductId, LastOutTime = SqlFunc.AggregateMax(s.CreateTime) }); var data = db.Queryable() .LeftJoin(flowQuery, (s, f) => s.ProductId == f.ProductId) .Where(s => s.StockQty > 0) .Select((s, f) => new ProductStockMonitorDto() { }, true) .ToList(); var data2 = db.Queryable() .LeftJoin(flowQuery, (s, f) => s.ProductId == f.ProductId) .Where(s => s.StockQty > 0) .Select() .ToList(); } } public class ProductStockFlow { [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = false)] public long Id { get; set; } public long ProductId { get; set; } /// /// 产品货号 /// public string ProductCode { get; set; } /// /// 产品名称 /// public string ProductName { get; set; } /// /// 发生数量 /// [SugarColumn(Length = 18, DecimalDigits = 4)] public decimal SettleQty { get; set; } /// /// 发生类型 /// public string SettleType { get; set; } /// /// 备注 /// [SugarColumn(IsNullable = true)] public string Remark { get; set; } public DateTime CreateTime { get; set; } } public class ProductStock { [SugarColumn(IsNullable = false, IsPrimaryKey = true, IsIdentity = false)] public long Id { get; set; } public long ProductId { get; set; } /// /// 产品货号 /// public string ProductCode { get; set; } /// /// 产品名称 /// public string ProductName { get; set; } /// /// 库存数量 /// [SugarColumn(Length = 18, DecimalDigits = 4)] public decimal StockQty { get; set; } } public class ProductStockMonitorDto { public long ProductId { get; set; } /// /// 产品货号 /// public string ProductCode { get; set; } /// /// 产品名称 /// public string ProductName { get; set; } /// /// 库存数量 /// public decimal StockQty { get; set; } /// /// 最后出库时间 /// public DateTime? LastOutTime { get; set; } } }