I recently upgraded from EntityFramework 5 to 6 via the NuGet updater. Everything seemed to go well and I built and executed my application. When I tried to retrieve the first entity from the database, I received this error:
The property 'UpdatedDate' is not a Byte array. IsRowVersion can only be configured for Byte array properties.
Here is the piece of code it is referring to:
[Timestamp]
public virtual DateTime UpdatedDate { get; set; }
I tried removing the timestamp attribute, but got the same error regardless. How do I fix this so I can run my application with EF6?
Property Mapping. The Property method is used to configure attributes for each property belonging to an entity or complex type.
The Entity Framework Core Fluent API HasDefaultValue method is used to specify the default value for a database column mapped to a property.
Configuring a primary key By convention, a property named Id or <type name>Id will be configured as the primary key of an entity. Owned entity types use different rules to define keys. You can configure a single property to be the primary key of an entity as follows: Data Annotations.
Entity Framework Fluent API is used to configure domain classes to override conventions. EF Fluent API is based on a Fluent API design pattern (a.k.a Fluent Interface) where the result is formulated by method chaining. In Entity Framework Core, the ModelBuilder class acts as a Fluent API.
Attributes in EF
If you use [TimeStamp]
attribute, then the property should be byte[]
This is then mapped to Rowversion in SQL server
If you want some other field type as a concurrency field.
The use the attribute [ConcurrencyCheck]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With