Issues with Tutorial: Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
kap
Posts: 4
Joined: Sun 18 Jan 2015 12:17

Issues with Tutorial: Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL

Post by kap » Thu 24 Sep 2015 10:58

Hello,

I got issues following this tutorial: Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL

I am sure that I am fulfilling the requriements:

Code: Select all

VS 2013 Update 5
Entity Framework:

Code: Select all

PM> install-package entityframework
'EntityFramework 6.1.3' already installed.
AspNet_Identity_Application already has a reference to 'EntityFramework 6.1.3'.
dotConnect for MySQL: 8.3.379.0 (pro licence)

References in project:

Code: Select all

Devart.Data.MySql.Entity
c:\Program Files (x86)\Devart\dotConnect\MySQL\Entity\EF6\Devart.Data.MySql.Entity.dll
8.3.379.6

Code: Select all

EntityFramework
...AspNet_Identity_Application\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll
6.0.0.0


When I follow the steps to the end of this tutorial and I start my application i get the following error message:

Code: Select all

The 'Instance' member of the Entity Framework provider type 'Devart.Data.MySql.Entity.MySqlEntityProviderServices, Devart.Data.MySql.Entity, Version=8.3.379.0, Culture=neutral, PublicKeyToken=09af7300eec23701' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Error in Line 24:

Code: Select all

Source Error:


Line 22:     public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
Line 23:     {
Line 24:         public ApplicationDbContext() <-- Error!
Line 25:             : base("DefaultConnection", throwIfV1Schema: false)
Line 26:         {
Any Ideas what I can do?

Thank you for your support.

Best regards,

kap

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Issues with Tutorial: Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL

Post by Shalex » Thu 24 Sep 2015 17:05

Please check the version (x.x.x.x) you have specified on the fifth step of the Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL tutorial. You have installed the 8.3.379 version of dotConnect for MySQL (Tools > MySQL > About), haven't you? In this case the version specified should be 8.3.379.6.

kap
Posts: 4
Joined: Sun 18 Jan 2015 12:17

Re: Issues with Tutorial: Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL

Post by kap » Fri 25 Sep 2015 09:05

Hello Shalex,

thank you very much. Changing the version number in the config file fixed the issue.

I got a second question, maybe you can also answer it:

After I was able to run the application, I tried to register myself as a new user. With the first try I run into following error:

Code: Select all

Conflicting configuration settings were specified for property 'UserName' on type 'Microsoft.AspNet.Identity.EntityFramework.IdentityUser`4[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Microsoft.AspNet.Identity.EntityFramework.IdentityUserLogin, Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Microsoft.AspNet.Identity.EntityFramework.IdentityUserRole, Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35],[Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim, Microsoft.AspNet.Identity.EntityFramework, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]':
MaxLength = 256 conflicts with MaxLength = 255
In line 155

Code: Select all

Line 153:            {
Line 154:                var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
Line 155:                var result = await UserManager.CreateAsync(user, model.Password);
Line 156:                if (result.Succeeded)
Line 157:                {
So I changed the OnModelCreating function to:

Code: Select all

protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {

            base.OnModelCreating(modelBuilder);

            modelBuilder
                .Entity<IdentityRole>()
                .Property(p => p.Name)
                .HasMaxLength(255);

            modelBuilder
                .Entity<IdentityUser>()
                .Property(p => p.UserName)
                .HasMaxLength(256); <-- setting this value from 255 to 256

            modelBuilder
              .Properties()
              .Where(p => p.PropertyType == typeof(string) &&
                          !p.Name.Contains("Id") &&
                          !p.Name.Contains("Provider"))
              .Configure(p => p.HasMaxLength(255));

        }
The code is running, but I am not sure if this is really the answer to this issue.

Can someone confirm?

Best regards,

kap

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Issues with Tutorial: Using Entity Framework Implementation of ASP.NET Identity 2.0 for MySQL

Post by Shalex » Thu 01 Oct 2015 10:51

kap wrote:

Code: Select all

            modelBuilder
                .Entity<IdentityUser>()
                .Property(p => p.UserName)
                .HasMaxLength(256); <-- setting this value from 255 to 256
The code is running, but I am not sure if this is really the answer to this issue.

Can someone confirm?
We confirm. Thank you for your report. We will update the dotConnect for MySQL documentation.

Post Reply