1

Question.
How to perform CRUD operations on JetEntityFrameworkProvider?

Description.
I want to apply Entity Framework to work with MS Access.
I am using: JetEntityFrameworkProvider.
I created a project.
I am running debugging.
Result: Error: "Table 'Planet2' already exists.".

Table. ____ enter image description here

Project.
____

ContextDB.cs

using System.Data.Entity;    
namespace ConsoleApp.Model
{
    class ContextDB : DbContext
    {
        public ContextDB() : base("DefaultConnection")
        {

        }

        public DbSet<Planet2> Planets { get; set; }                
    }    
}

Planet2.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; }        
    }
}

Program.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;
        }
    }
}

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>

    <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>
climivin
  • 181
  • 8
  • Does this answer your question? [How can I disable code first migrations](https://stackoverflow.com/questions/14654055/how-can-i-disable-code-first-migrations) – bubi Jul 23 '20 at 06:23
  • The issue is related to migrations. JetEntityFrameworkProvider supports migrations. If you already have the tables on your DB you need to disable migrations. – bubi Jul 23 '20 at 06:25

0 Answers0