I need help for a dynamic where clause over relational tables (one to many) in LinqToSql.
User select conditions from page. (there is 4 input that u
Are you looking for something like this, where you define the "base" query, and then evaluate parameters to determine if a where clause is appropriate?
var result = (from x in context.X
select x);
if(some condition)
{
result = result.AsQueryable().Where(x => x.companyName == name);
}
if(some other condition)
{
result = result.AsQueryable().Where(x => x.companyTitle == title);
}
//return result.ToList();
//return result.FirstOrDefault();
//return result.Count(); //etc
I noticed in one of your comments you mentioned your tables are not joined by a foreign key? I'm not sure how you get a one-to-many relationship without some kind of referential integrity or relationship?