4

I've this query in my C# file and it works fine:

from var in db.database_1 
where var.database_2.primarycat.Length > 0 && var.meditype.Contains("All")   
xxx               
select new XElement("id", new XElement("temp", var.database_2.name)

Now, I want to insert this query in the where argument at xxx:

AND name IN (
SELECT primarycat
from database_2
GROUP BY primarycat
HAVING COUNT(*) > 1)

Can somebody help me?

Mine W
  • 55
  • 4

2 Answers2

5

A simple sub query should do this:

from var in db.database_1 
where var.database_2.primarycat.Length > 0
    && var.meditype.Contains("All")   
    && (from cat in db.database_2
        group cat by cat.primarycat into g
        where g.Count() > 1
        select g.Key).Contains(var.name)
select new XElement("id", new XElement("temp", var.database_2.name)
Nuffin
  • 3,882
  • 18
  • 34
1

Use a sub select. Check out this thread which answers pretty much the same thing.

how to do subquery in LINQ

Community
  • 1
  • 1
Moriya
  • 7,750
  • 3
  • 35
  • 53