Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,
I am using a linq query to retrieve data from multiple tables using joins
In the view page when the user enters data on any of the field then all the resp data of that particular must be displayed
Upto here,its working well and good
But my problem is
for e.g, when the user inputs one field data that belongs to userid=1 and second field data belonging to userid=2 then data belonging to userid=2 is getting displayed
Actully it should show invalid match
Please anyone provide me solution to this.
Am posting my query below.Not understanding where i went wrong and where to fix
C#
var query = from s in dbContext.User_details
                               join j in dbContext.User_addresses on s.Userid equals j.Userid
                               join k in dbContext.Userworkdetails on j.Userid equals k.Userid
                               join l in dbContext.Useredudetails on k.Userid equals l.Userid

 select new { l.Userid,l.City, s.Firstname, k.Company, l.College, j.State, s.Lastname, j.Country };

                   if (!string.IsNullOrEmpty(FirstName))
                       query = query.Where(s => s.Firstname == FirstName);



                   if (!string.IsNullOrEmpty(City))
                       query = query.Where(l => l.City == City);

                   if (!string.IsNullOrEmpty(State))
                       query = query.Where(j => j.State == State);


                   if (!string.IsNullOrEmpty(Country))
                       query = query.Where(j => j.Country == Country);


                   if (!string.IsNullOrEmpty(LastName))
                      query = query.Where(s => s.Lastname == LastName);


                   if (!string.IsNullOrEmpty(Company))
                       query = query.Where(k => k.Company == Company);


                   if (!string.IsNullOrEmpty(College))
                       query = query.Where(l => l.College == College);


                   var results = (from r in query.ToList()


                                  select new
                                  {
                                      Ft = r.Firstname,
                                      Lt = r.Lastname,
                                      Ct = r.City,
                                      Co = r.Country,
                                      Com = r.Company,
                                      Col = r.College,
                                      St = r.State,
                                      Id=r.Userid

                                  }).ToArray();

Thanks
Posted
Updated 18-May-12 18:36pm
v2

1 solution

C#
var query = from s in dbContext.User_details
                   join j in dbContext.User_addresses on s.Userid equals j.Userid
                   join k in dbContext.Userworkdetails on s.Userid equals k.Userid
                   join l in dbContext.Useredudetails on s.Userid equals l.Userid


THis may sole your problem
 
Share this answer
 
Comments
Sahithi Pinisetty 19-May-12 1:00am    
Thanks for your solution,
Here userid is the primary key,it did not make any change even though i implemented changes u told
Thanks
Sahithi Pinisetty 19-May-12 2:09am    
Can anyone please provide solution to this.. its really urgent

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