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?

2 Answers 2

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)
Sign up to request clarification or add additional context in comments.

Comments

1

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

how to do subquery in LINQ

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.