小编mip*_*ips的帖子

如何停止添加dbo的Entity Framework 5迁移.成为关键名称?

我开始使用Entity Framework 4.3 Code First进行手动迁移和SQL Express 2008并最近更新到EF5(在VS 2010中),并注意到现在当我更改类似外键约束时,迁移代码会添加"dbo".到表名的开头,因此它构造的外键名称对于现有约束是不正确的(现在通常看起来很奇怪).

EF 4.3中的原始迁移脚本(注意ForeignKey("Products",t => t.Product_Id)):

    CreateTable(
        "Products",
        c => new
            {
                Id = c.Int(nullable: false, identity: true),
                ProductName = c.String(),
            })
        .PrimaryKey(t => t.Id);

    CreateTable(
        "KitComponents",
        c => new
            {
                Id = c.Int(nullable: false, identity: true),
                Component_Id = c.Int(),
                Product_Id = c.Int(),
            })
        .PrimaryKey(t => t.Id)
        .ForeignKey("Products", t => t.Component_Id)
        .ForeignKey("Products", t => t.Product_Id)
        .Index(t => t.Component_Id)
        .Index(t => t.Product_Id);
Run Code Online (Sandbox Code Playgroud)

生成的外键名称:FK_KitComponents_Products_Product_Id FK_KitComponents_Products_Component_Id

如果我然后升级到EF5并更改外键,则迁移代码看起来像(注意"dbo.KitComponents"和"dbo.Products"而不是"KitComponents"和"Products"):

DropForeignKey("dbo.KitComponents", "Product_Id", "dbo.Products");
DropIndex("dbo.KitComponents", …
Run Code Online (Sandbox Code Playgroud)

entity-framework entity-framework-5

30
推荐指数
2
解决办法
9467
查看次数

Jenkins没有使用新的MSBuild恢复目标恢复NuGet包

我们有一个.net完整框架WPF应用程序,我们已经从.net 4.6.2移动到4.7.1,同时更改为csproj文件中的PackageReference而不是packages.config.

在开发机器上构建似乎很好并且下载和恢复了包,但是当我们使用Jenkins构建我们的Windows Server 2012构建服务器时,nuget包似乎无法正确恢复.

我们使用MSBuild v15.5和最新的"msbuild/restore"命令在构建时恢复软件包.注意:使用以前调用"nuget restore"的方法确实有效,但我们现在应该能够使用msbuild/restore.

包恢复过程似乎正在查看正确的NuGet服务器,并且看起来没有错误地进行恢复(这是在Jenkins上编译的测试解决方案以隔离问题):

Restore:
  Restoring packages for c:\Jenkins\workspace\Test\ConsoleApp1\ConsoleApp1.csproj...
  Committing restore...
  Generating MSBuild file c:\Jenkins\workspace\Test\ConsoleApp1\obj\ConsoleApp1.csproj.nuget.g.props.
  Generating MSBuild file c:\Jenkins\workspace\Test\ConsoleApp1\obj\ConsoleApp1.csproj.nuget.g.targets.
  Writing lock file to disk. Path: c:\Jenkins\workspace\Test\ConsoleApp1\obj\project.assets.json
  Restore completed in 577.05 ms for c:\Jenkins\workspace\Test\ConsoleApp1\ConsoleApp1.csproj.

  NuGet Config files used:
      c:\Jenkins\workspace\Test\NuGet.Config
      C:\Windows\system32\config\systemprofile\AppData\Roaming\NuGet\NuGet.Config

  Feeds used:
      http://devbuild/NuGetHost/nuget
      https://api.nuget.org/v3/index.json
Done Building Project "c:\Jenkins\workspace\Test\ConsoleApp1.sln" (Restore target(s)).
Run Code Online (Sandbox Code Playgroud)

但是当msbuild编译代码时,我们得到以下错误,看起来像NuGet还没有被下载:

CSC : error CS0006: Metadata file 'C:\Windows\system32\config\systemprofile\.nuget\packages\log4net\2.0.8\lib\net45-full\log4net.dll' …
Run Code Online (Sandbox Code Playgroud)

c# msbuild nuget jenkins

25
推荐指数
3
解决办法
8617
查看次数

EF 6 Code First,使用包含在导航属性上的外键ID更改会导致"发生引用完整性约束违规"错误

我正在使用Entity Framework 6.1.3,并且我有一个场景,我使用其导航属性检索实体(使用Include())并将其与上下文断开连接,更改外键ID然后将其重新附加到新的DbContext:

// Init the Db
using (var db = new MyContext())
{
   var theWarranty = new ProductWarranty { WarrantyName = "The Warranty" };
   var newWarranty = new ProductWarranty { WarrantyName = "New Warranty" };
   var brand = new ProductBrand { BrandName = "The Brand", DefaultWarranty = theWarranty };

   db.ProductBrands.Add(brand);
   db.ProductWarranties.Add(newWarranty);

   db.SaveChanges();
}

// Load the detached Brand
ProductBrand detachedBrand;
using (var db = new MyContext())
{
   detachedBrand = db.ProductBrands.AsNoTracking()
      .Include(b => b.DefaultWarranty)  // <<< If this line is …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework ef-code-first dbcontext entity-framework-6

5
推荐指数
1
解决办法
3184
查看次数