How to split a Datetime-like column from an Entity Framework query?

Asked

Viewed 69 times

2

I own a field of the kind DateTime? (void allowed) which is in the full date/hour formed (dd/MM/yyyy hh:mm:ss).

I need to display the date and time in separate columns in a datagridview. I tried to use the DbFunctions.TruncateTime(x.Data.Value.Date) as I saw in suggestions from here, but gives the following error:

System.Notsupportedexception: 'The specified type Member 'Date' is not supported in LINQ to Entities. Only initializers, Entity Members, and Entity navigation properties are supported.'

  • dataGridView is winforms ?

  • 2

    I think the problem is only in the display... no need to mess with the data... puts the code of how you are loading / displaying this that will help solve

  • 1

    @Rovannlinhalis I was editing the question and I realized this too. If so, signal me to delete the answer, please.

  • @Rovannlinhalis, yeah. winforms. Thanks for your help, guys.

  • put the code you populate to datagridview then, and if you generate the columns by visual tool or via code

1 answer

6


You have to use the support function DbFunctions.TruncateTime. To use this function you need to pass the DateTime complete, not the member Date

DbFunctions.TruncateTime(x.Data)
  • Thanks, @LINQ. Worked :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.