This is not the first time I have been stuck on collections. I’m missing something here and feeling not just a little frustrated. This code snippet is designed return the count of the number of ‘restaurant reviews’ in the REVIEW db that have a specified ‘restaurant id.’ Again I’m getting the a “cannot implicitly covert type” error.
Thanks in advance!
public IEnumerable<string> getNumReviews(int RestID)
{
var NumReviews = from REVIEW in db.REVIEWs
where REVIEW.REST_ID == RestID
group REVIEW by REVIEW.REVIEW_ID into t
select new { REVIEW_ID = t.Key, TagCount = t.Count() };
return NumReviews;
}
NumReviewsis anIEnumerable<anonymous type>, not anIEnumerable<string>. In particular, you’re returing an enumeration of objects that include aREVIEW_IDand a count of the tags for each review.Your best option is to declare a type to encapsulate that information:
Then, select that object from the method: