bubibubi / JetEntityFrameworkProvider

Microsoft Access (Jet) Entity Framework provider
89 stars 26 forks source link

No Entity Framework provider found for the ADO.NET provider with invariant name 'JetEntityFrameworkProvider' #53

Open it19862 opened 4 years ago

it19862 commented 4 years ago

Error. No Entity Framework provider found for the ADO.NET provider with invariant name 'JetEntityFrameworkProvider'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. "

Question: How do I resolve the error?

Used by

Description. I am trying to connect to MS Access database - db_test_01.accdb. I have created a console application. I am using the instruction: https://www.youtube.com/watch?v=mI0un8jjqL8

I get an error: see the "Error" section above.

Picture 2020-07-20_21-04-13

Code App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <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:\test\csharp\vs\db\db_test_01.accdb"
             providerName="JetEntityFrameworkProvider"/>
    </connectionStrings>
</configuration>

Person.cs

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace ConsoleApp
{
    class Person
    {
        public Person()
        {
            OwnerCars = new List<Car>();
        }

        public int Id { get; set; }

        [MaxLength(10)]
        public string Name{ get; set; }

        public virtual ICollection<Car> OwnerCars { get; set; }
    }    

}

Car.cs

using System.ComponentModel.DataAnnotations;

namespace ConsoleApp
{   
    class Car
    {        
        public int Id { get; set; }

        [MaxLength(10)]
        public string Name { get; set; }

        public virtual Person Owner { get; set; }
    }

}

Context.cs

using System.Data.Entity;

namespace ConsoleApp
{
    class Context : DbContext
    {

        public Context() : base("DefaultConnection")
        {

        }

        public DbSet<Car> Cars{ get; set; }
        public DbSet<Person> People { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Person>()
                .HasMany(_ => _.OwnerCars)
                .WithOptional(_ => _.Owner);
        }

    }
}

Program.cs

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            JetEntityFrameworkProvider.JetConnection.ShowSqlStatements = true;
            using (var context = new Context())
            {
                context.Cars.Count();
            }
            Console.ReadLine();
        }
    }
}
bubibubi commented 4 years ago

This is a section of an App.Config. Could you check if your is similar?


</configuration>
  <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>
it19862 commented 4 years ago

@bubibubi

This is a section of an App.Config. Could you check if your is similar?

</configuration>
  <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>

Question: How to connect these ("App.config" -bubibubi) + "App.config" (My)?

I do not understand you My "App.config" (My). `<?xml version="1.0" encoding="utf-8" ?>

` You are providing "App.config" -bubibubi. ``` ```
it19862 commented 4 years ago

@bubibubi The topic is closed. Thank.