SQL query in C # (Linq)

I have this request 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 request into the where argument in xxx :

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

Can someone help me?

+4
source share
2 answers

A simple subquery 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) 
+5
source

Use an extra choice. Check out this thread, which is almost completely the same.

how to perform a subquery in LINQ

+1
source

All Articles