Entity framework joins

user686483 picture user686483 · Jul 12, 2011 · Viewed 11k times · Source

I'm using the entity framework 4.0 and I'm having some issues with the syntax of my query. I'm trying to join 2 tables and pass a parameter to find the value at the same time.I would like find all of the products in table 2 by finding the correlating value in table 1.

Can someone help me out with syntax please?

Thanks in advance.

sample data

table 1

ID  productID   categoryID  
361 571         16  
362 572         17  
363 573         16  
364 574         19  
365 575         26

table 2

productID   productCode

571     sku

572     sku

573     sku

574     sku

575     sku 




var q = from i in context.table1
                            from it in context.table2
                            join <not sure> 
                            where i.categoryID == it.categoryID and < parameter >
                          select e).Skip(value).Take(value));

                    foreach (var g in q)
                    {
                        Response.Write(g.productID);
                    }

Answer

Akhil picture Akhil · Jul 13, 2011
var q = from i in context.table1
        join it in context.table2 on i.productID equals it.productID
        where i.categoryID == it.categoryID and it.productCode = xyz
      select i).Skip(value).Take(value));