问题。
如何对 JetEntityFrameworkProvider 执行 CRUD 操作?
描述。
我想应用实体框架与 MS Access 一起工作。
我正在使用:JetEntityFrameworkProvider。
我创建了一个项目。
我正在调试。
结果:错误:“表 'Planet2' 已存在。”。
上下文数据库.cs
using System.Data.Entity;
namespace ConsoleApp.Model
{
class ContextDB : DbContext
{
public ContextDB() : base("DefaultConnection")
{
}
public DbSet<Planet2> Planets { get; set; }
}
}
行星2.cs
namespace ConsoleApp.Model
{
class Planet2
{
// Context.cs
public string Id { get; set; }
public string PlanetName { get; set; }
public int DistanceFromSun { get; set; }
public string Inhabitance { get; set; }
}
}
程序.cs
using ConsoleApp.Model;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
ContextDB contextDB = new ContextDB();
// var resullt = contextDB.Planets.ToList();
var resullt = from tabl in contextDB.Planets
select tabl;
}
}
}
应用程序配置
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Provider=Microsoft.ACE.OleDB.12.0;Data source=c:\db_test_01.accdb"
providerName="JetEntityFrameworkProvider"/>
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="JetEntityFrameworkProvider" />
<add invariant="JetEntityFrameworkProvider" name="Jet Entity Framework Provider" description="Jet Entity Framework Provider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider" />
</DbProviderFactories>
</system.data>
</configuration>