Reputation: 79
I have this IQueryable here :
First problem:
The error that is shown in the picture. I cant find the cast applicable to that situation. I was wondering if anyone had an idea where to find it.
Second problem:
I want to be able to compare the query result to a string stored in one of my view models.
The way i would call the IQueryable would be like :
var code = securityCodeCheck(item.SelectedDistrict);
and my comparison would be like:
if (item.DistrictCode == code)
{
return view();
}
else{
return RedirectToAction(....);
}
how would I go about being able to compare the 2 successfully?
Upvotes: 0
Views: 223
Reputation: 17680
For the first problem you are selecting District.securityCode
(which i assume is a string)
Try to select District
as that would be the right IQueryable
to fix the error since the method clearly defines it as a return type.
Code change would be as below.
var query = from District in db.Districts
where District.leaID.Equals(district)
select District;
For problem 2.
You can use as below.
var code = securityCodeCheck(item.SelectedDistrict);
if(item.DistrictCode == code.First().securityCode)
{
//do stuff
}
Upvotes: 1