Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi
I want a linq code equivalent of this:

SQL
Select Company.Name, 
       Person.Name
             From Person, Company
                  Where Company.PersonID = Person.ID And 
                              Company.City = N"Bolton"


Entity names: Company, Person
Posted

try this Code

C#
var QueryResult = from p in Person
                  join c in Company on p.ID equals c.PersonID 
                  where c.City == N"Bolton"
                  select new { c.Name, p.Name };

Click here for more information
Vote or Accept solution
If this will help you
thanks
 
Share this answer
 
v2
Comments
Fardan 12-Feb-12 3:12am    
Thank you
zyck 12-Feb-12 3:47am    
your welcome (n_n)
Use Linqer [^] tool to translate any SQL statement to LINQ.
 
Share this answer
 
Comments
Fardan 12-Feb-12 3:08am    
Thank you. Not my answer but a useful link.
Wonde Tadesse 13-Mar-12 23:38pm    
You 're welcome.
Espen Harlinn 28-Feb-12 14:19pm    
Good advice :)
Wonde Tadesse 13-Mar-12 23:38pm    
Thanks
VJ Reddy 23-Apr-12 19:31pm    
+5
Wow - that's pretty trivial. Something like

C#
from c in categories
        join p in products on c equals p.Category into ps
        select new { Category = c, Products = ps };


That is a sample from the site below. You should be able to convert this syntax to suit your requirements.

http://msdn.microsoft.com/en-us/vstudio/aa336746[^]
 
Share this answer
 
Comments
Espen Harlinn 28-Feb-12 14:20pm    
5'ed! :)
Check this article
Learn SQL to LINQ (Visual Representation)[^]

EDIT
For this kind of things, use conversion tools for example LINQPad[^]
 
Share this answer
 
v2
Comments
Fardan 12-Feb-12 3:21am    
Not my anser.
The article doesn't include a query with more that 1 from.
(From Person, Company)
thatraja 12-Feb-12 3:39am    
Check updated answer
Espen Harlinn 28-Feb-12 14:22pm    
Good reply :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900