Entity Framework - Azure Table 存储提供程序 - 映射时间戳时出错

Entity Framework - Azure Table Storage Provider - Error While Mapping Timestamp

我目前正在使用 EF 访问 Azure 存储 Table:EntityFramework.AzureTableStorage 7.0.0-beta1

配置模型时,我已将 TableEntity 的时间戳 属性 映射到模型的 属性 :

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
    }
}

插入新实体时,一切听起来都不错,我可以使用 LastModification 检索新创建的实体,但如果我实例化第二个 DbContext,则无法检索我的实体:

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");
}

异常详情:

Microsoft.WindowsAzure.Storage.StorageException was unhandled HResult=-2146233088 Message=Cannot read value of type 'DateTimeOffset' from '13' Source=Microsoft.WindowsAzure.Storage

从 Azure 存储帐户检索数据时映射似乎不起作用。

有谁知道解决方法(除了删除时间戳映射)?

如前所述,EF Azure Table Storage beta1 是一个原型,目前已停产。另见 。它不在积极开发中(在撰写本文时)。