Why can’t I return as a new custom class (cms.bo.Site) which implements ISite?
public IQueryable<ISite> GetSites()
{
return (from site in Db.Sites select new cms.bo.Site(site.id, site.name));
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically LINQ to SQL doesn’t know what that constructor will do – it wants to try to convert that into a SQL query, but doesn’t know how. Do you need to be able to add extra bits to the query afterwards? If not, you could do:
EDIT: I had missed the variance aspect, and was assuming the query was failing at execution time. It’s definitely worth trying just the call to
Cast<ISite>()as per tvanfosson’s answer – but if that doesn’t work, try the above 🙂