Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to entities parametrized constructor Datetime

i know that Linq to entities does not support parametrized constructors, but how to do this pls ?:

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

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 this?

like image 800
Petr Pražák Avatar asked Jul 10 '12 08:07

Petr Pražák


Video Answer


1 Answers

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

These helper methods were built to translate to a SQL equivalent, as noted in the remarks of that link:

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

This function is translated to a corresponding function in the database.

like image 124
Brian Mains Avatar answered Sep 28 '22 14:09

Brian Mains