5

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?

Filburt
  • 17,626
  • 12
  • 64
  • 115
Petr Pražák
  • 191
  • 2
  • 10

1 Answers1

11

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.

Brian Mains
  • 50,520
  • 35
  • 148
  • 257