如何使用,实体框架结合嵌套的Cros连接和左连接

时间:2018-11-27 09:47:12

标签: .net join core

我想用entiy框架编写以下代码。 有点困难。我在等你的帮助。

select* from LocaleStringResource as locale 
cross join Language language
left join LocaleStringResourceLanguage localeLang 
on locale.Id = localeLang.RecordId and 
language.ID = localeLang.LanguageId

1 个答案:

答案 0 :(得分:0)

我假设了一些信息,因为您没有给我们提供有关实体的足够信息。我想您正在尝试这样做。试试这个,让我们知道这是否是正确的方法。

var query =  (from locale in _context.LocaleStringResource 
                 from language in _context.Language 
                 join localeLangBefLJ in _context.LocaleStringResourceLanguage on new { field1 = locale.Id, field2 = language.ID } equals new { field1 = localeLangBefLJ.RecordId, field2 = localeLangBefLJ.LanguageId }
                      into localeLang 
                 from x in localeLang.DefaultIfEmpty()
                 select new
                 {
                     locale,
                     language, 
                     x
                 })