1

how to convert nested select query to linq statment in asp.net mvc

select * from ProviderPostComments M where M.Id not in (
select c.Id from ProviderPostComments as c , BlockUsers as b 
where  (
(c.RequesterID = b.RequesterId and b.RequesterID= '9E58484C-D01C-49B0-8BCC-2C22EE468D8A')
or 
(c.RequesterID = b.ProviderId and b.ProviderId  = '9E58484C-D01C-49B0-8BCC-2C22EE468D8A')
)
and b.IsDeleted=0

)
  • 2
    Which query provider are you using? Entity Framework? What have you tried? – Crowcoder Jan 04 '22 at 12:36
  • yes , entity freamwork – Lujain Alskran Jan 04 '22 at 12:45
  • What version of EF? core or normal? Show us your entities – Caius Jard Jan 04 '22 at 12:47
  • yes normal EF ` var query = db.ProviderComments.AsNoTracking() .Include(arg => arg.Provider) .Include(arg => arg.Provider.BlockUsers) .Include(arg => arg.Requester.BlockUsers) .Include(arg => arg.Post) .Where(arg => !arg.IsDeleted && !arg.Post.IsDeleted) ` – Lujain Alskran Jan 04 '22 at 12:50
  • OK, so I've managed to establish you're using EF, not EFCore.. But that's about it. What version of EF? (Say a number like "6.4"). Show us your entities? (Edit the question to include code that looks like `class ProviderPostComment{ ... virtual ICollection BlockUsers ...`) – Caius Jard Jan 04 '22 at 17:11
  • Perhaps my [SQL to LINQ Recipe](https://stackoverflow.com/questions/49245160/sql-to-linq-with-multiple-join-count-and-left-join/49245786#49245786) might help you. – NetMage Jan 04 '22 at 20:01

1 Answers1

0

Hello below is a sample nested LINQ

you can modify that as you wish

yourlist.SelectMany(h => h.Itemtype)
      .Select(rt => rt.Item.Id)
      .Distinct()
      .ToArray();
Anto king
  • 1,222
  • 1
  • 13
  • 26