Linq join table with collection

I have a collection that I am compiling from a linq query, and I would like to use this collection as a connection for another query. How to do it?

thank

+3
source share
5 answers

LINQ 101 Samples

The copied LINQ statements from here

string[] categories = new string[]{ 
    "Beverages", 
    "Condiments", 
    "Vegetables", 
    "Dairy Products", 
    "Seafood" };

List<Product> products = GetProductList();

var q =
    from c in categories
    join p in products on c equals p.Category
    select new { Category = c, p.ProductName };

foreach (var v in q)
{
    Console.WriteLine(v.ProductName + ": " + v.Category);
}
+5
source

try it

var query2 = from c in db.YourTable
        join q in query1 on c.Id equals q.Id
        select c;

Where query1 uses your first collection created from linq query.

+2
source

You should be able to do this:

 List<Product> products = GetProductList(); //collection

 var q = from c in categories
         join p in products on c equals p.Category into ps
         select new { Category = c, Products = ps };
0
source

Below is the Linq query I wrote that does just that. This is a Linq to SQL query that is combined into a local collection.

int[] keyList = new int[] { 7064, 7065, 6242 };

var query = (from child in ETAModule
        join parent in ETA on child.ExpID equals parent.ExpID
        where child.ID >= 65490442
        where keyList.Contains(child.ExpID)
        orderby child.ID
        select new { EtaModule = child, Eta = parent });
0
source

... not much information is provided, but here is a very simple example.

var firstCollection = List<YourClassNameHere>(); // this is your pre-existing collection
var results = from o in firstCollection
               join i in SomeOtherCollection on o.JoinField equals i.JoinField
               select i; // or whatever you like
0
source

Source: https://habr.com/ru/post/1775323/


All Articles