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

This is my linq query.

I have a two tables one is Reviews and other one is Master_country.
present I got result only Reviews table using bellow query.
Now I need data from 2nd Table.
var reviwdata = from x in context.CompanyReviews.Where(k => k.Cid == compId).OrderByDescending(o => o.Sno).Take(take).Skip(pageSize) select x;
take and pagesize used for paging on Repeater. That is Dynamic values.
The result is
id     name  Countryid
1       nag  2
2       raj  2
3       raj  2

in my Master_county table 
country id  Location
   2        Hyderabd
   3        chennai

How to assign my data from Master_country Table
I want like this using Reviews and Master_country Tables.
id      name         countryname
1       nag           Hyderabad
2       raj           Hyderabad
3       raj           hyderabad 


Please Help me...
Thank you...
Posted
Updated 5-Jun-14 1:34am
v2
Comments
Codes DeCodes 5-Jun-14 7:20am    
question is bit unclear. anyway you need to use join to get data from two tables based on key.
ZurdoDev 5-Jun-14 7:23am    
What's your question?
Ajith K Gatty 5-Jun-14 7:24am    
and also see this link "http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b"

CSS
var result =
        from x in context.Master_county
        join y in context.CompanyReviews on x equals y.Countryid into ps
        from p in ps
        select new { x.is,x.name,x.countryid, p.countryname }
 
Share this answer
 
Comments
Pravuprasad 5-Jun-14 7:37am    
See the above answer probably it may help you out.
Ajith K Gatty 5-Jun-14 7:57am    
yes. It looks fine to me.
C#
var reviwdata = (from j in context.CompanyReviews
                            join s in context.Companies on new { Cid = (Int32)j.Cid } equals new { Cid = s.Id }
                            where
                            s.Id == compId
                            select new
                            {
                                j.Sno,
                                j.Title,
                                j.Cons,
                                j.Date,
                                j.Rating,
                                j.CorrentOrFormer,
                                j.JobTitle,
                                j.Pros,
                                s.CompanyName
                            }).OrderByDescending(j=>j.Sno).Take(take).Skip(pageSize);
 
Share this answer
 

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