How to map a TIME-like column in Entity Framework 6?

Asked

Viewed 406 times

5

I am using this mapping to a SQL Server DATETIME field:

Property(X => X.DatNascimento).HasColumnName("DAT_NASCIMENTO").HasColumnType("datetime");

But I have another field that is only TIME that I do not know how to configure:

Property(X => X.HoraLimiteInferiorEntrada).HasColumnName("HORA_LIM_INF_ENTRADA").HasColumnType(??????);

1 answer

5


The guy is TimeSpan. Just make sure that you use at least SQL Server 2008, which is the first version of SQL Server that supports the guy time:

public TimeSpan IntervaloMaximoAlmoco { get; set; }

To Fluent API, use:

Property(X => X.IntervaloMaximoAlmoco).HasColumnName("HOR_INT_ALMOCO").HasColumnType("time");
  • And . Hascolumntype(???????) I put datetime myself?

  • 2

    No. Use time.

  • I updated the question with the error that gave.

  • I just had to change the guy. I was DateTime before.

Browser other questions tagged

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