这是我面临的问题。
Linqer在转换何时" H" 包含另一个案例的部分。这是原始的SQL:
SELECT [REC_FNAME] ,
[REC_MNAME] ,
[REC_LNAME] ,
[REC_SLNAME] ,
[ADDRESS_RECEIVER] ,
[ID_CITY_RECEIVER] ,
[ID_STATE_RECEIVER] ,
[ZIP_RECEIVER] ,
[ID_COUNTRY_RECEIVER] ,
C.NAME_CITY ,
ST.NAME_STATE ,
CO.NAME_COUNTRY ,
[PHONE1_RECEIVER] ,
[PHONE2_RECEIVER] ,
[NET_AMOUNT_RECEIVER] , -- send amount
ISNULL([TELEX_RECEIVER], 0.00) , -- transfer fee
[STATE_TAX] , -- source tax
[DEST_COUNTRY_TAX] ,
[TOTAL_RECEIVER] , -- total amount sent
[RATE_CHANGE_RECEIVER] , -- exchange rate
[TOTAL_PAY_RECEIVER] , -- receive amount
[ID_CURRENY] ,
[ID_FLAG_RECEIVER] ,
CASE [ID_FLAG_RECEIVER]
WHEN 'A' THEN 'VOID'
WHEN 'C' THEN 'CANCEL'
WHEN 'E' THEN 'EXPIRED'
WHEN 'H'
THEN ( SELECT CASE WHEN EXISTS ( SELECT 1
FROM [dba].[MOTIVO_HOLD] MH
WITH ( NOLOCK )
WHERE MH.ID_BRANCH = R.ID_BRANCH
AND MH.ID_RECEIVER = R.ID_RECEIVER
AND MH.TYPE_MOTIVO_HOLD = 70 )
THEN 'STAGED'
ELSE 'HOLD'
END
)
WHEN 'I' THEN 'DONE'
WHEN 'P' THEN 'PAID'
WHEN 'T' THEN 'TRANSFERED'
END AS TransactionStatus ,
[RECEIVER_DATE_AVAILABLE] ,
[DATE_RECEIVER] ,
[CLAVE_RECEIVER] ,
[ID_BRANCH] ,
[ID_SENDER] ,
[ID_RECEIVER] ,
[BRANCH_PAY_RECEIVER]
FROM [dba].[RECEIVER] R
INNER JOIN dba.STATE ST ON ST.ID_STATE = R.ID_STATE_RECEIVER
AND R.ID_COUNTRY_RECEIVER = ST.ID_COUNTRY
INNER JOIN dba.CITY C ON C.ID_CITY = R.ID_CITY_RECEIVER
AND C.ID_STATE = R.ID_STATE_RECEIVER
AND C.ID_COUNTRY = R.ID_COUNTRY_RECEIVER
INNER JOIN dba.COUNTRY CO ON CO.ID_COUNTRY = ST.ID_COUNTRY
WHERE [ID_BRANCH] = @idBranch
AND DATE_RECEIVER BETWEEN @startDate AND GETDATE()
ORDER BY DATE_RECEIVER DESC
所以我删除了当" H" 我得到了一个有效的声明:但是我需要加入" H"解决与之相关的真实描述的案例。
帮助将不胜感激!
Here is the Linq statement I have to date:<br>
var models1 =
_context.Receivers
.Where(r => r.ID_BRANCH == "A00070" &&
r.DATE_RECEIVER >=
(DateTime)
SqlFunctions.DateAdd(
"day", -10,
SqlFunctions.GetDate()) &&
r.DATE_RECEIVER <=
SqlFunctions.GetDate())
.Join(_context.Senders,
r => new {r.ID_SENDER, r.ID_BRANCH},
s => new {s.ID_SENDER, s.ID_BRANCH},
(r, s) =>
new
{
s.NAME_SENDER,
r.NAME_RECEIVER,
r.TOTAL_PAY_RECEIVER,
Status =
r.ID_FLAG_RECEIVER.Replace("A", "VOID")
.Replace("C", "CANCEL")
.Replace("E", "EXPIRED")
.Replace("I", "DONE")
.Replace("P", "PAID")
.Replace("T", "TRANSFERED")
.Replace("H", "Hold"),
r.DATE_RECEIVER,
r.ID_CASHIER
})
.OrderByDescending(r => r.DATE_RECEIVER)
.Project().To<MoneyTransferListViewModel>();
答案 0 :(得分:0)
在LINQ中,您需要将其作为let关键字来执行,该关键字执行子查询,无论该项是否为H.我不认为在LINQ中您可以在您的场景中执行此操作。替换。
唯一的问题是,我只知道一种LINQ查询方式,即:
from r in _context.Receivers
let b = (_context.Motivo_Hold
.Where(i => i.ID_BRANCH == r.ID_BRANCH && i.ID_RECEIVER == r.ID_RECEIVER)
.Select(i => new { .flag = 1 }))
.
select new {
.r.ID_FLAG_RECEIVER.Replace("A", "VOID")
.Replace("H", (b.flag == 1 ? "Staged" : "Hold"))
}
类似的东西......某些语法可能已关闭,但这是一般方法