简体   繁体   English

UWP SQL Server迁移不起作用

[英]UWP SQL Server migration not working

I installed the latest version of Windows 10 (fall creators update) and Visual Studio 2017 (15.4). 我安装了Windows 10的最新版本(秋季创建者更新)和Visual Studio 2017(15.4)。

I created an UWP app targeted to major version and installed by Nuget: 我创建了一个针对主要版本的UWP应用,并由Nuget安装:

  • microsoft.entityframeworkcore.tools microsoft.entityframeworkcore.tools
  • microsoft.entityframeworkcore.sqlserver microsoft.entityframeworkcore.sqlserver

This is my code: 这是我的代码:

[Table("tbProva")]
public class Prova
{
    public Prova()
    {
        Indirizzi = new List<Indirizzo>();
    }

    [Key]
    public Guid Id { get; set; }

    [MaxLength(250)]
    public string Nome { get; set; }
    public ICollection<Indirizzo> Indirizzi { get; set; }
}

public class ProvaConfig : IEntityTypeConfiguration<Prova>
{
    public void Configure(EntityTypeBuilder<Prova> builder)
    {
        builder.HasMany(c => c.Indirizzi)
            .WithOne(c => c.Prova)
            .HasForeignKey(c => c.IdProva)
            .OnDelete(DeleteBehavior.Cascade);
    }
}

[Table("tbIndirizzi")]
public class Indirizzo
{
    [Key]
    public Guid Id { get; set; }
    [MaxLength(250)]
    public string Strada { get; set; }
    [MaxLength(10)]
    public string Civico { get; set; }
    public Prova Prova { get; set; }
    public Guid IdProva { get; set; }
}

public class DcContext : DbContext
{
    public DbSet<Prova> tbProva { get; set; }
    public DbSet<Indirizzo> tbIndirizzi { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer("Server=Europa;Database=ProvaDb;Trusted_Connection=True;");
    }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfiguration<Prova>(new ProvaConfig());
    }
}

If I run migration, I get this result: 如果运行迁移,则会得到以下结果:

PM> Add-Migration poi 

System.TypeLoadException: Non è stato possibile caricare il tipo 'System.Globalization.CultureInfo' dall'assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. System.TypeLoadException:可能不会发生的故障,例如“ System.Globalization.CultureInfo” dall程序集“ System.Runtime,版本= 4.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a”。

If I remove the navigation properties from model and I do not override OnModelCreating , it works fine. 如果我从模型中删除了导航属性,并且没有覆盖OnModelCreating ,那么它将正常工作。

Thanks 谢谢

Ensure that the System.Globalization NuGet packge is installed and up-to-date. 确保已安装System.Globalization NuGet Packge,并且它是最新的。

Also, if you are going to use EntityFramework please make sure that you installed the microsoft.entityframeworkcore package is installed too. 另外,如果要使用EntityFramework,请确保还安装了microsoft.entityframeworkcore软件包。

This should be a known issue,see issue #9666 . 这应该是一个已知问题,请参阅问题#9666

While testing EF Core 2.0 with .NET UWP 6.0 we found that there are new types that present similar problems. 在使用.NET UWP 6.0测试EF Core 2.0时,我们发现有些新类型也存在类似问题。 Eg: System.TypeLoadException: Could not load type 'System.Globalization.CultureInfo' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. 例如:System.TypeLoadException:无法从程序集“ System.Runtime,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”中加载类型“ System.Globalization.CultureInfo”。 System.TypeLoadException: Could not load type 'System.MarshalByRefObject' from assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. System.TypeLoadException:无法从程序集“ System.Runtime,版本= 4.0.0.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”中加载类型“ System.MarshalByRefObject”。

One example of above exception was DataAnnotations . 上述例外的一个例子是DataAnnotations And in your code snippet just referenced the System.ComponentModel.DataAnnotations namespace. 并且在您的代码片段中引用了System.ComponentModel.DataAnnotations命名空间。

And it seems like this patch bug is approved for the 2.0.x patch. 而且似乎此补丁程序错误已批准用于2.0.x补丁程序。 See issue #9827 . 参见问题#9827

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM