Linq for Entities Parameterized Datetime Constructor

I know that Linq for objects does not support parameterized constructors, but how to do this ?:

date = new DateTime(int.Parse(SqlFunctions.StringConvert(l.rok).Trim()), int.Parse(SqlFunctions.StringConvert(l.mesic).Trim()), 1)

The whole example:

var objects = from object in GetObjects()
                   select new MyObject{
                   name = object.name;
                   date = new DateTime(object.rok,object.month,object.day)
                   }

How to do it?

+5
source share
1 answer

Use the EntityFunctions CreateDateTime method found here: http://msdn.microsoft.com/en-us/library/system.data.objects.entityfunctions.createdatetime

These helper methods were created to translate into the SQL equivalent, as noted in the notes of this link:

You cannot call this function directly. This function can only appear in a LINQ to Entities query.

This function is translated into the corresponding function in the database.

+10
source

All Articles