Entity framework core 如何使用实体框架核心创建T-SQL交叉应用程序?

Entity framework core 如何使用实体框架核心创建T-SQL交叉应用程序?,entity-framework-core,cross-apply,Entity Framework Core,Cross Apply,我想用EntityFramework核心创建一个查询,它有多个内部连接和一个交叉应用 我可以很好地创建内部连接,但似乎无法使交叉应用程序正常工作 谷歌搜索是否真的没发现什么有用的东西 尝试使用实体框架linq语句执行不同的操作,但到目前为止没有任何效果 这是我到目前为止得到的EF查询: comCommunicationContext .通讯 .AsNoTracking() .Where(c=>c.Label.InternalName==labelName&& c、 Businesstrans

我想用EntityFramework核心创建一个查询,它有多个内部连接和一个交叉应用

我可以很好地创建内部连接,但似乎无法使交叉应用程序正常工作

  • 谷歌搜索是否真的没发现什么有用的东西
  • 尝试使用实体框架linq语句执行不同的操作,但到目前为止没有任何效果
这是我到目前为止得到的EF查询:

comCommunicationContext
.通讯
.AsNoTracking()
.Where(c=>c.Label.InternalName==labelName&&
c、 Businesstransaction.DocumentType.DocumentTypeName==DocumentType&&
c、 Businesstransaction.SourceSystem.SourceSystemName==SourceSystem)
.Join(comCommunicationContext.CommunicationOutputChannel,CommunicationOneEntity=>CommunicationOneEntity.CommunicationId,communicationOutputChannelEntity=>communicationOutputChannelEntity.CommunicationId,(CommunicationOneEntity,communicationOutputChannelEntity)=>new{Communication=communicationEntity,CommunicationOutputChannel=communicationOutputChannelEntity})
.其中(y=>y.CommunicationOutputChannel.OutputChannel==OutputChannel)
.Join(comCommunicationContext.CommunicationStatusOutputChannel)。
其中(x=>x.Status==“to process”),communicationOutputChannelEntity=>communicationOutputChannelEntity.CommunicationOutputChannelId,communicationStatusOutputChannelEntity=>communicationStatusOutputChannelEntity.CommunicationOutputChannelId,(外部,内部)=>new Communication(){CommunicationDataEnriched=outer.Communication.CommunicationDataEnriched})
这将生成以下T-SQL查询:

选择[c].[communicationdatariched]
来自[通信]作为[c]
在[c].[BusinessTransactionId]=[c.Businesstransaction].[BusinessTransactionId]上将[Businesstransactions]作为[c.Businesstransaction]进行内部联接
在[c.Businesstransaction].[DocumentTypeId]=[c.Businesstransaction.DocumentType].[DocumentTypeId]上将[DocumentTypes]作为[c.Businesstransaction.DocumentType]进行内部联接
将[SourceSystems]作为[c.Businesstransaction].[SourceSystemId]=[c.Businesstransaction.SourceSystem].[SourceSystemId]上的[c.Businesstransaction.SourceSystem]进行内部联接
在[c].[LabelId]=[c.Label].[LabelId]上将[Labels]作为[c.Label]进行内部联接
将[CommunicationOutputChannel]作为[c].[CommunicationId]=[CommunicationOutputChannel].[CommunicationId]上的[CommunicationOutputChannel]进行内部联接
内连接(
选择[x]*
从[CommunicationStatusOutputChannel]作为[x]发送
其中[x].[Status]=“待处理”
)在[CommunicationOutputChannels].[CommunicationOutputChannelId]=[t].[CommunicationOutputChannelId]上作为[t]
其中(([c.Label].[InternalName]='labelname')和([c.Businesstransaction.DocumentType].[DocumentTypeName]='DocumentType'))和([c.Businesstransaction.SourceSystem].[SourceSystemName]='sourcessysem'))和([CommunicationationOutputChannel].[OutputChannel]='email'))
我想发送到数据库的是:

选择[c].[communicationdatariched]
来自[通信]作为[c]
在[c].[BusinessTransactionId]=[c.Businesstransaction].[BusinessTransactionId]上将[Businesstransactions]作为[c.Businesstransaction]进行内部联接
在[c.Businesstransaction].[DocumentTypeId]=[c.Businesstransaction.DocumentType].[DocumentTypeId]上将[DocumentTypes]作为[c.Businesstransaction.DocumentType]进行内部联接
将[SourceSystems]作为[c.Businesstransaction].[SourceSystemId]=[c.Businesstransaction.SourceSystem].[SourceSystemId]上的[c.Businesstransaction.SourceSystem]进行内部联接
在[c].[LabelId]=[c.Label].[LabelId]上将[Labels]作为[c.Label]进行内部联接
将[CommunicationOutputChannel]作为[c].[CommunicationId]=[CommunicationOutputChannel].[CommunicationId]上的[CommunicationOutputChannel]进行内部联接
交叉应用(
选择顶部1[x]*
从[CommunicationStatusOutputChannel]作为[x]发送
其中[x].[Status]=“待处理”
和[x].[CommunicationOutputChannelId]=[CommunicationOutputChannels].[CommunicationOutputChannelId]
订单依据[x]。createdOn DESC
)[t]
其中(([c.Label].[InternalName]='labelname')和([c.Businesstransaction.DocumentType].[DocumentTypeName]='DocumentType'))和([c.Businesstransaction.SourceSystem].[SourceSystemName]='sourcessysem'))和([CommunicationationOutputChannel].[OutputChannel]='email'))
对象
CommunicationOutputChannel
具有类型为
ICollection
的导航属性
CommunicationStatusOutputChannel
(在
CommunicationOutputChannel
CommunicationStatusOutputChannel
实体之间存在一对多关系)


因此,表
通信输出通道
通信状态输出通道
之间的最后一个
内部联接
应该是一个
交叉应用

无需担心。找到了一个适合我的解决方案

var q=来自comCommunicationContext.Communication.Where中的c(c=>c.Label.InternalName==labelName&&c.Businesstransaction.DocumentType.DocumentTypeName==DocumentType&&c.Businesstransaction.SourceSystem.SourceSystemName==SourceSystem)
在comCommunicationContext.CommunicationOutputChannel中加入coc
关于c.CommunicationId等于coc.CommunicationId
从comCommunicationContext.CommunicationStatusOutputChannel.Where中的csoc(x=>x.CommunicationOutputChannelId==coc.CommunicationOutputChannelId)。OrderByDescending(y=>y.CreatedOn)。取(1)
其中csoc.Status==“要处理”
选择new Communication(){CommunicationDataEnriched=c.CommunicationDataEnriched}
;