I have the following LINQ query that works fine:
var comps = (from c in tc.companies
join r in tc.registry
on c.Key equals r.Key
select new { FieldValue=r.FieldValue, Name=c.Name, Company=c.Company,Industry=c.Industry,Rank=c.Rank});
Now I want the query to only return those records where FieldValue equals to the value submitted from TextBox1
I have tried:
var comps = (from c in tc.companies
join r in tc.registry
on c.Key equals r.Key
where r.FieldValue==TextBox1
select new { FieldValue=r.FieldValue, Name=c.Name, Company=c.Company,Industry=c.Industry,Rank=c.Rank});
return View(comps);
and
var comps = (from c in tc.companies
join r in tc.registry
on c.Key equals r.Key
where r.FieldValue==TextBox1
select new { FieldValue=r.FieldValue, Name=c.Name, Company=c.Company,Industry=c.Industry,Rank=c.Rank});
comps=comps.Where(x => x.FieldValue== TextBox1);
return View(comps);
But neither returns any data. What am I doing wrong?
Update:
public ActionResult Index(string TextBox1)
{
if (TextBox1 != null)
{
var comps = (from c in tc.companies
join r in tc.registry
on c.Key equals r.Key
where r.FieldValue==TextBox1
select new { FieldValue=r.FieldValue, Name=c.Name, Company=c.Company,Industry=c.Industry,Rank=c.Rank});
return View(comps);
}
}
SOLVED! Answer is below! Not what I thought - reversing the table order in the query worked. Interesting pafr is that the query without a filter worked regardless of table order