2

I have a Members table with a column containing date of birth; by default the datatype for the dateofbirth column is varchar.

How can I convert the string to a DateTime using Entity Framework?

I have tried something like this:

let dob = eclipse.members.Take(1)
                         .Select(x => report.member_Dob)
                         .Cast<DateTime>()
                         .FirstOrDefault()

But it does not work for me and I can't change the schema.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Glory Raj
  • 17,397
  • 27
  • 100
  • 203

2 Answers2

1

Unfortunately, L2E does not support any string to DateTime conversions. There are a couple workarounds, such as parsing the string and creating a DateTime object inside the Linq query to compare against, but those are verbose and ugly.

I'd suggest creating your L2E query as best you can, then use Linq to Objects to return your final dataset.

-1

what about this:

let dob =eclipse.members.Take(1).Select(x=> DateTime.Parse(report.member_Dob)).FirstOrDefault();

?

Arnaud F.
  • 8,252
  • 11
  • 53
  • 102
  • same error .....LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression – Glory Raj Sep 16 '11 at 10:54