So basically, I try here to transfer this query in LINQ.
DECLARE @p1 UniqueIdentifier SET @p1 = AC1D85C1-28F1-46A3-9C6A-3B7446609A2A
DECLARE @p2 UniqueIdentifier SET @p2 = NEWID()
SELECT
[MTD].[Description],
[MTD].[MessageTypeID],
ISNULL([AMT].[ApplicationMessageTypeID], NEWID()),
ISNULL([AMT].[EventForwardingRuleID], 1001 )
FROM [dbo].[MessageType] as [MT]
INNER JOIN [dbo].[MessageTypeDescription] AS [MTD]
ON [MT].[MessageTypeID] = [MTD].[MessageTypeID]
LEFT OUTER JOIN [dbo].[ApplicationMessageType] AS [AMT]
ON [AMT].[MessageTypeID] = [MT].[MessageTypeID]
AND ( [AMT].[ApplicationID] = @p1 OR [AMT].[ApplicationID] IS NULL )
WHERE [MTD].[Culture] = fr
我基本上知道,问询应该像以下一点:
(from mt in db.MessageTypes
join mtd in db.MessageTypeDescriptions
on mt.MessageTypeID equals mtd.MessageTypeID
join amt in db.ApplicationMessageTypes
on new { mt.MessageTypeID, (applicationId || null) } equals new { amt.MessageTypeID, amt.ApplicationID }
into appMessageTypes
from amt in appMessageTypes.DefaultIfEmpty()
where mtd.Culture == culture
select new ApplicationEditEventTypeModel
{
ApplicationMessageTypeID = amt.ApplicationMessageTypeID == null ? Guid.NewGuid() : amt.ApplicationMessageTypeID,
Description = mtd.Description,
MessageTypeID = mtd.MessageTypeID,
EventForwardingRuleID = amt.EventForwardingRuleID == null ? 0 : amt.EventForwardingRuleID
});
我确实不相信的那部分是“ApplicationMessageTypes”。 多个左翼加入询问一,即使用<代码>new{}等于新的{>>,但在此情形下,我有两个条款<代码>[AMT].[应用ID] = @p1 OR [AMT]。
如果我使用<代码>新版{mt”。 InformationTypeID, new{app 页: 1 InformationTypeID, amt.ApplicationID }? 这似乎过于奇怪。