I'm starting with a SQL query that selects against a view & looks like this:
SET @id = ...
SET @variableDate = ...
SELECT Id,
dbo.fnGreaterDateTime(ViewDate,@variableDate) AS GreaterDate,
FROM vwExample
WHERE Id = @id
The SQL function fnGreaterDateTime
works as you would expect, returning the greater of the two values passed in.
I'm having trouble converting this to a LINQ query when using EF & RIA services. In my Domain Service, I would like to be able to do something like the following:
public IQueryable<ExampleViewResult> GetExampleViewResults(int id, DateTime variableDate)
{
var query = from r in this.ObjectContext.ExampleViewResults
where r.Id == id
select new ExampleViewResult
{
Id = r.Id,
ViewDate = (r.ViewDate > variableDate) ? r.ViewDate : variableDate
}
return query;
}
But when I call this method I receive an error that says "The entity or complex type ExampleViewResult cannot be constructed in a LINQ to Entities query".
I tried following some advice over in this thread, but when I have the domain service method return a list of DTOs instead, the auto-code generation doesn't include the method for use in my domain context.
Any ideas?