I am currently accessing an Azure Storage Table using EF: EntityFramework.AzureTableStorage 7.0.0-beta1
When configuring the model, I've mapped the timestamp property of the TableEntity to a property of my model :
public class Subscription
{
public string Environment { get; set; }
public string Name { get; set; }
public DateTimeOffset LastModification { get; set; }
...
...
}
public class EF7Context : DbContext
{
public DbSet<Subscription> Subscriptions { get; set; }
protected override void OnConfiguring(DbContextOptions options)
{
options.UseAzureTableStorage("MyconnectionString");
}
protected override void OnModelCreating(Microsoft.Data.Entity.Metadata.ModelBuilder modelBuilder)
{
// Configure the Azure Table Storage
modelBuilder.Entity<Subscription>()
.ForAzureTableStorage() // Data are stored in an Azure Table Storage.
.Table("SubscriptionDev") // Name of the Table in the Azure Storage Account
.Timestamp(s => s.LastModification) // Map the timestamp
.PartitionAndRowKey(s => s.Environment, s => s.Name); // Map the partition and the row key
}
}
When inserting new entity, every thing sounds good, I can retrieve the newly created entity with the LastModification but if I instanciate a second DbContext, I can't retrieve my entity:
using (var context = new EF7Context())
{
// Create the entity
var subscription = new Subscription() {Environment = "Dev", Name = "subscriptionName" };
context.Subscriptions.Add(subscription);
context.SaveChanges();
// Retrieve the entity in the same context => I assume entity has been cached ?
subscription = context.Subscriptions.SingleOrDefault(s => s.Name == "subscriptionName");
}
// Create new instance of the DbContext
using (var context = new EF7Context())
{
// Exception thrown here
var subscription = context.Subscriptions.SingleOrDefault(s => s.Name == "subscriptionName");
}
Exception details:
Microsoft.WindowsAzure.Storage.StorageException was unhandled HResult=-2146233088 Message=Cannot read value of type 'DateTimeOffset' from '13' Source=Microsoft.WindowsAzure.Storage
It seems that the mapping does not work while retrieving data from the Azure Storage Account.
Does anyone know a workaround (except removing the timestamp mapping) ?