Adding TableColumn annotation in Fluent API

Monday, May 12, 2014

I am trying to build a common Data model to use with my backend as well as different services. Right now i am using Azure Mobile Services to retrieve data. However, i cannot use Data Annotations in my data model, or use the base class EntityData.

This is possible, however, i would like to still have the properties UpdatedAt and CreatedAt, that are available through this base class. From the source i can see, that this properties are annotated like this:

public DateTimeOffset? CreatedAt { get; set; }

public DateTimeOffset? UpdatedAt { get; set; }

I have tried adding the required statements in my DbContext through use of the Fluent API, like so:

modelBuilder.Types<MyEntity>().Configure(config => config
.Property(x => x.CreatedAt)
.HasColumnAnnotation("TableColumn", TableColumnType.CreatedAt));

modelBuilder.Types<MyEntity>().Configure(config => config
.Property(x => x.UpdatedAt)
.HasColumnAnnotation("TableColumn", TableColumnType.UpdatedAt));

However, this does not work, i am getting an exception. How can i apply this column annotations with Fluent API instead of using Attributes?