EF 6 filtering child collections

后端 未结 3 1208
臣服心动
臣服心动 2021-01-04 11:46

I\'m trying to migrate old project from Linq2Sql to EF6 and I got following issue.

This project is multilingual (i.e. all texts have more than 1 translation) and I h

3条回答
  •  一生所求
    2021-01-04 12:23

    NOT tested AND not perfect in terms of performance due to how include works... I would do it manually but here is an example of what you could do.

    var result = dc.ExampleEntity1
                 .Include(x => x.TextEntry)
                 .Include(x => x.TextEntry.LocalizedContents)
                 .Include(x => x.TextEntry.LocalizedContents.Local)
                 .Where(x => x.id == 'ExampleEntity1Key'
                          && x.TextEntity.LocalContent.Local.Id == 'Value'
                  )
                 .FirstOrDefault();
    

    This would end up with an object of ExampleEntity1 with all navigation eager loaded.... where Local is matched on an id.

    you could then get the Local like..

    var listLocalsForExampleEnitity = result.TextEntry.LocalizedContents.Local.ToList();
    

    or just call them from where ever as they are already in mem.

    Hope this helps

提交回复
热议问题