Reputation: 2146
Am trying to write a very simple select statement like below using Linq against Entity data model
trying to achieve
"Select * from SAPCostcentre where costcentermanager="mike";
Created my edmx and add a new class to write my DAO like below using linq but it doesn't like it.
public void ResourceCollection(string CostCenter)
{
string name = "Mike";
var context = new ScheduALLDAL.SAPCostCentre();
var query = from c in context.CostCentreManager where context.CostCentreManager = name select c;
var costcenter = query.ToList();
}
It throws exception "can not convert type string to bool
here "context.CostCentreManager = name"
in my db design costcentermanger
data type is varchar
. Please some one throw me a light what am missing here or the right approach .
Upvotes: 0
Views: 418
Reputation: 12837
var query = from c in context.CostCentreManager
where context.CostCentreManager == name
select c;
Upvotes: 1
Reputation: 75296
It should be:
var query = from c in context.CostCentreManager
where context.CostCentreManager == name select c;
use ==
instead of =
Upvotes: 1
Reputation: 10129
This is because you need to use a double equals sign (==). By using a single equals sign you are trying to assign context.CostCentreManager to "name".
Upvotes: 1
Reputation: 13763
It should be ==
as you are making a Boolean evaluation. The rest of your code should be OK then :)
Upvotes: 1