Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I am using two tables(A and B).

A Table has TempId,Email,PhoneNo,userid fields
B Table has Userid,Name fields

Now I want to fetch all records from Table A, then with Table A userid I want to fetch the name from the Table B.

I want Linq query for this.

Any tips will be appreciated.

Regards,
RK
Posted
Updated 6-Jun-13 1:00am
v2

use joins here either left join or right join
SQL
select A.Email,A.TempId,A.PhoneNo,B.Name from A Inner Join B on A.userid=B.userid
 
Share this answer
 
v2
Comments
_Amy 6-Jun-13 23:13pm    
Sorry, but "Not Accepted". OP is asking LINQ query.
SQL
SELECT * FROM A
INNER JOIN B on A.TempId = B.UserId
 
Share this answer
 
v2
Comments
_Amy 6-Jun-13 23:13pm    
Sorry, but "Not Accepted". OP is asking LINQ query.
Try this:
C#
var result = from a in TableA.AsEnumerable()
            join b in TableB.AsEnumerable() on a.Field<string>("Userid") equals 
            a.Field<string>("Userid")
            select new
            {
               TempId = a.Field<string>("TempId"),
               Email = a.Field<string>("Email"),
               PhoneNo = a.Field<string>("PhoneNo"),
               Userid= a.Field<string>("Userid"),
               Name = b.Field<string>("Name"),
            };




--Amit
 
Share this answer
 
v2
Hi Friends,

I Solved this by myself, thanks for your research and answers,

here is the query that I used

var query = (from A in context.ATable
join B in Context.BTable on A.UserId equals B.UserId
where ((A.UserId != userID)
select new { A.TempId,A.Email, A.PhoneNo,B.Username });

Thanks,
RK
 
Share this answer
 
C#
SELECT * FROM A INNER JOIN B on A.userid=B.Userid
 
Share this answer
 
Comments
_Amy 6-Jun-13 23:13pm    
Sorry, but "Not Accepted". OP is asking LINQ query.

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