Closed hyke123 closed 2 years ago
SQL本来就不支持一对查询吧 ,你的SQL是什么样的
db.Ado.SqlQuery<T1,T2>("select 1 from xx; select xx from yy") 目前ADO查询只有这种多条SQL一起映射
可能是我表述的不够清楚 想要的效果就是类似dapper这种
var twoClass = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
JoinType.Left, o.Id == i.OrderId,
JoinType.Left, o.CustomId == c.Id
))
.Select((o, i, c) => new { o,i}).ToList();
生成的SQL SELECT [o].[Id] AS [Order.Id] , [o].[Name] AS [Order.Name] , [o].[Price] AS [Order.Price] , [o].[CreateTime] AS [Order.CreateTime] , [o].[CustomId] AS [Order.CustomId] , [i].[ItemId] AS [OrderItem.ItemId] , [i].[OrderId] AS [OrderItem.OrderId] , [i].[Price] AS [OrderItem.Price] , [i].[CreateTime] AS [OrderItem.CreateTime] FROM [Order] o Left JOIN [OrderDetail] i ON ( [o].[Id] = [i].[OrderId] ) Left JOIN [Custom] c ON ( [o].[CustomId] = [c].[Id] )
var twoClass = db.Queryable<Order, OrderItem, Custom>((o, i, c) => new JoinQueryInfos(
JoinType.Left, o.Id == i.OrderId,
JoinType.Left, o.CustomId == c.Id
))
.Select((o, i, c) => new { o,i}).ToList();
生成的SQL SELECT [o].[Id] AS [Order.Id] , [o].[Name] AS [Order.Name] , [o].[Price] AS [Order.Price] , [o].[CreateTime] AS [Order.CreateTime] , [o].[CustomId] AS [Order.CustomId] , [i].[ItemId] AS [OrderItem.ItemId] , [i].[OrderId] AS [OrderItem.OrderId] , [i].[Price] AS [OrderItem.Price] , [i].[CreateTime] AS [OrderItem.CreateTime] FROM [Order] o Left JOIN [OrderDetail] i ON ( [o].[Id] = [i].[OrderId] ) Left JOIN [Custom] c ON ( [o].[CustomId] = [c].[Id] )
不用SQL用联表查询是可以的
var x= db.SqlQueryable<dynamic>("SELECT [o].[Id] AS [Order.Id] , [o].[Name] AS [Order.Name] , [o].[Price] AS [Order.Price] , [o].[CreateTime] AS [Order.CreateTime] , [o].[CustomId] AS [Order.CustomId] , [i].[ItemId] AS [OrderItem.ItemId] , [i].[OrderId] AS [OrderItem.OrderId] , [i].[Price] AS [OrderItem.Price] , [i].[CreateTime] AS [OrderItem.CreateTime] FROM [Order] o Inner JOIN [OrderDetail] i ON ( [o].[Id] = [i].[OrderId] )")
.Select(it=>new { o=new Order(),i=new OrderItem()})
.Select("*").ToList();
有方案了 这样命名可以自动映射
SqlQueryable 或者Ado.SqlQuery 连表一对多的查询结果怎么映射到类的集合属性上