【发布时间】:2021-08-27 11:31:13
【问题描述】:
var data = await dbContext.Set<OwnerData>().FromSqlRaw(@"
SELECT [OWP].[OwnerProfileId],
SELECT [OWP].[Email],
FROM [user].[OwnerProfile] AS [OWP]
CAST(ISNULL([OWB].[CustomBalance], 0) AS decimal(18, 3)) AS [CustomBalance]
INNER JOIN [user].[OwnerBalance] AS [OWB] ON [OWB].[OwnerProfileId] = [OWP].[OwnerProfileId]
WHERE [ThirdPartyRefId] = {0}", ownerProfileId)
.ToListAsync();
我把它改写成这样的linq表达式
var data = await _context.Set<OwnerProfile>()
.Include(x => x.OwnerBalances)
.Where(x => x.ThirdPartyRefId== ownerProfileId)
.ToListAsync();
不知道怎么设置
CAST(ISNULL([OWB].[CustomBalance], 0) AS decimal(18, 3)) AS [CustomBalance]
进入 lambda 查询
【问题讨论】:
-
你的实体类的
CustomBalance属性是什么类型的?为什么不坚持使用原始 SQL? -
decimalin .NET 没有可配置的精度或比例