I have a database I'm trying to query via Entity Framework and then select the return data into an collection output object - while using IQueryable
to improve performance - and then apply a couple functions to the resultant data that comes back from the DB query. For one, I can't use .ToLocalTime()
on a DateTime
object as it's not supported. I get this error:
LINQ to Entities does not recognize the method 'System.DateTime ToLocalTime()' method, and this method cannot be translated into a store expression.
If I try to call other custom functions on returned data I get a similar exception.
Here is my code below:
IQueryable<DatabaseEntityType> query = context.MyEntities.Where(c=> c.Finished == true);
db.MyEntities.OrderByDescending(c => c.DateCreated).Select(c => new OutputObject()
{
Guid = c.Guid,
Notes = c.Notes,
DateCreated = c.DateCreated.ToLocalTime(),
Related = String.Join("<br/>", c.RelatedEntities.Select(c => c.TractNumber)),
Others = String.Join("<br/>", c.OtherRelatedEntities.Select(c => c.OwnerName)),
DocumentType = EnumUtility.GetDocumentTypeString(c.DocumentType),
Uploader = c.Account.FirstName + " " + c.Account.LastName,
});
Is there any way to do this while still using IQueryable
? I have a large data set that needs to be filtered on the server without using a .ToList()
.