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
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