Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Entity framework core 实体框架-Azure表存储提供程序-枚举支持_Entity Framework Core_Azure Table Storage - Fatal编程技术网

Entity framework core 实体框架-Azure表存储提供程序-枚举支持

Entity framework core 实体框架-Azure表存储提供程序-枚举支持,entity-framework-core,azure-table-storage,Entity Framework Core,Azure Table Storage,我实际上是在为EF()使用Azure存储表提供程序 最后,我介绍了如何配置DbContext: public class Subscription { public string Environment { get; set; } public string Name { get; set; } ... ... } public class EF7Context : DbContext { public DbS

我实际上是在为EF()使用Azure存储表提供程序

最后,我介绍了如何配置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
    }
}
我已将这些属性添加到
订阅
类中:

public int PriorityId { get; set; }

public QueuePriority Priority
{
    get { return (QueuePriority)PriorityId; }
    set { PriorityId = (int)value; }
}
并在EF配置中将
Priority
属性声明为shadow,这样我就不会在Azure表中同时存储PriorityId和Priority:

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();
}
protected override void onmodel创建(Microsoft.Data.Entity.Metadata.ModelBuilder ModelBuilder)
{   
...
//我们不映射数据库中的枚举,只映射ID。
modelBuilder.Entity().Property(s=>s.Priority.Shadow();
}
所以我想知道是否有更好的方法来实现这一点和/或EF.AzureTableStorage的下一个版本是否将支持Enum


谢谢

你看过动态ORM吗?有了它,你就不需要像实体框架那样进行这种设置,而且它支持Azure表存储。节省了我们很多时间。我不了解它的基本原理,但它会在您编写代码时自动映射您的所有类型,因此您无需定义任何实体等。

EF Azure Table Storage beta1是一个已停止使用的原型。另请参见

Azure Table Storage SDK version>8.0.0已经支持枚举和许多其他简单和复杂的属性类型,因此您实际上不需要为此使用额外的框架

您可以使用TableEntity简单地展平POCO对象。展平方法:

将展开的字典写入表存储。阅读时,只需将EntityProperty字典传递给
TableEntity.ConvertBack
方法:

它将重新组合原始对象,包括其
Enum
和其他类型的属性


您的实体类不需要从
TableEntity
类继承,也不需要实现
ITableEntity
接口,它们可以是具有简单属性的POCO对象,也可以具有自己的嵌套复杂属性以及对象图的许多层
flatte
ConvertBack
方法都支持。

感谢链接。这似乎很有趣,但不是免费的:我知道这个世界上没有免费的东西。无论如何,这并没有回答关于修复或解决方法的mt问题…@Thomas我没有在免费版本中使用它,但这里有一个,我确信它有一些限制。我不是实体框架专家,所以我不知道您最初问题的答案,但我想我会尽力帮助您。祝你好运
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();
}