How to do a split of a DateTime column from a query by the Entity Framework?

2

I have a field of type DateTime? (null allowed) that is in the complete date / time format (dd / mm / yyyy hh: mm: ss).

I need to display the date and time in separate columns in a datagridview. I tried to use DbFunctions.TruncateTime(x.Data.Value.Date) as I saw in suggestions here, but it 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. '

    
asked by anonymous 15.06.2018 / 14:55

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 Date member

DbFunctions.TruncateTime(x.Data)
    
15.06.2018 / 15:41