我的dll具有数据上下文
using rmclibrary.Model;
using System.Data.Entity;
namespace rmclibrary
{
public class RmcContext : DbContext
{
public RmcContext() : base("RmcContext")
{
}
public DbSet<Brand> Brands { get; set; }
// ...and etc
}
}
在Brand类中,我具有Check方法
public class Brand
{
[Key]
public int BrandId { get; set; }
public string UID1C { get; set; }
[Required]
public string Name { get; set; }
[Required]
public int Prefix { get; set; }
public void Check()
{
Console.WriteLine("nachalo");
using (var dc = new RmcContext())
{
var k = new Brand();
k.Name = "trrr";
k.Prefix = 4444;
dc.Brands.Add(k);
dc.SaveChanges();
}
}
}
app.config下面
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="RmcContext" connectionString="Server=localhost;Port=5432;User Id=postgres;Password=123456789;Database=rmctest;" providerName="Npgsql" />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
迁移和更新时不带任何动画问题
我在新控制台项目中添加的该dll并尝试使用Check方法
using rmclibrary.Model;
using System;
namespace DatabaseWorker
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("start");
var z = new Brand();
z.Check();
}
}
}
它停留在u sing (var dc = new RmcContext())
这行上
几分钟后给出错误:
System.Data.SqlClient.SqlException
HResult = 0x80131904
提供程序:SQL网络接口,错误:26