实体框架-Azure表存储提供程序-枚举支持 [英] Entity Framework - Azure Table Storage Provider - Enum Support
问题描述
我实际上使用的是EF的Azure存储表提供程序( EntityFramework.AzureTableStorage 7.0.0 -beta1 ).
I am actually using the Azure Storage Table provider for EF (EntityFramework.AzureTableStorage 7.0.0-beta1).
我已经结束了如何配置DbContext:
I've ended up how to configure the DbContext:
public class Subscription
{
public string Environment { get; set; }
public string Name { 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
.PartitionAndRowKey(s => s.Environment, s => s.Name); // Map the partition and the row key
}
}
但是现在我想添加一个枚举作为Subscription
模型的一部分.
我找到了一种解决方法:
But Now I would like to add an enum as part of the Subscription
model.
I've found a workaround to do this:
我有一个枚举:
public enum QueuePriority
{
High,
Low
}
我已经将这些属性添加到Subscription
类中:
I've added these properties to the Subscription
class:
public int PriorityId { get; set; }
public QueuePriority Priority
{
get { return (QueuePriority)PriorityId; }
set { PriorityId = (int)value; }
}
然后将Priority
属性声明为EF配置中的阴影,这样我就不会将PriorityId和Priority都存储在Azure表中:
And Declare the Priority
property as shadow in EF configuration so that I'm not going to have the PriorityId and the Priority stored both in the Azure Table :
protected override void OnModelCreating(Microsoft.Data.Entity.Metadata.ModelBuilder modelBuilder)
{
...
// We are not mapping the Enum in the database only the IDs.
modelBuilder.Entity<Subscription>().Property(s => s.Priority).Shadow();
}
所以我想知道是否有更好的方法来完成此操作,并且/或者是否有EF.AzureTableStorage的下一版本将支持Enum?
So I am wondering if there is a better way to accomplish this and/or If next versions of EF.AzureTableStorage is going to support Enum ?
谢谢
推荐答案
EF Azure表存储beta1是目前已停产的原型.另请参见 https://stackoverflow.com/a/35071077/2526265
EF Azure Table Storage beta1 was a prototype that has been discontinued for now. See also https://stackoverflow.com/a/35071077/2526265
这篇关于实体框架-Azure表存储提供程序-枚举支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!