Reputation: 27996
I have this LINQ query:
var query = from row in context.data_vault
group row by row.STATE into g
select new {
State = g.Key,
Count = g.Sum(row => row.SCORE),
Phones = g.Count(c => c.PHONE)
};
When executed, I get following error:
Cannot implicitly convert type 'string' to 'bool' at g.Count(c => c.PHONE)
Upvotes: 1
Views: 4253
Reputation: 30628
Count()
is expecting a predicate - something that returns a boolean. You've got it returning a string. I'm not sure what you're after, but if you wanted to count the number of non-blank phones, you would modify it to be
var query = from row in context.data_vault
group row by row.STATE into g
select new {
State = g.Key,
Count = g.Sum(row => row.SCORE),
Phones = g.Count(c => c.PHONE != "")
};
Upvotes: 0
Reputation: 6317
What are you trying to count? If you want to count non-null or non-empty phone numbers, you need to use g.Count(c => String.IsNullOrEmpty(c.PHONE)==false )
Upvotes: 0
Reputation: 101142
The Count method expects a function returning a boolean value. It looks like your PHONE property is a string, so this will not work.
What exactly are you trying to count?
Maybe you want all non-empty phone numbers or anything like that, try
g.Count(c => !String.IsNullOrWhitespace(c.PHONE))
Upvotes: 1