Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Sharing: Using MySql in ABP ASP.NET Core 1.1 project #3095


User avatar
0
jakeuj created

Current ASP.NET Core template is ASP.NET Core 1.1 <span style="color:#FF0000">NOT</span> Include module zero.

NuGet Package Install MySql.Data.EntityFrameworkCore [attachment=2:16v61bom]2017-05-03_15-35-37.png[/attachment:16v61bom] (I remove two package about mssql, too.)

Edit MyProject.EntityFrameworkCore.DbContextOptionsConfigurer.cs [attachment=1:16v61bom]2017-05-03_15-36-29.png[/attachment:16v61bom]

dbContextOptions.UseMySQL(connectionString);

Edit appsettings.json [attachment=0:16v61bom]2017-05-03_15-37-53.png[/attachment:16v61bom]

"Default": "Server=localhost; Database=GameDb; userid=root;pwd=;port=3306;sslmode=none;"

Then you can Add-Migration, Update-Database, use Repositories...ETC.

BTW, I got an error if use the project Include module zero.

A discriminator property cannot be set for the entity type 'EditionFeatureSetting' because it is not the root of an inheritance hierarchy.


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thank you for your sharing :).

    About the exception with module zero, official EFCore library provided by Oracle cannot doesn't automatically do registrations for derived classes.

    You can either use <a class="postlink" href="https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql">https://github.com/PomeloFoundation/Pom ... Core.MySql</a> or you need to define Discriminator column like this

    modelBuilder.Entity<FeatureSetting>(b =>
    {
        b.HasDiscriminator<string>("Discriminator")
            .HasValue<FeatureSetting>(nameof(FeatureSetting))
            .HasValue<EditionFeatureSetting>(nameof(EditionFeatureSetting))
            .HasValue<TenantFeatureSetting>(nameof(TenantFeatureSetting));
    });
    
    modelBuilder.Entity<PermissionSetting>(b =>
    {
        b.HasDiscriminator<string>("Discriminator")
            .HasValue<PermissionSetting>(nameof(PermissionSetting))
            .HasValue<RolePermissionSetting>(nameof(RolePermissionSetting))
            .HasValue<UserPermissionSetting>(nameof(UserPermissionSetting));
    });
    

    Thanks.

  • User Avatar
    0
    jakeuj created

    I override OnModelCreating, then I got an error when Add-Migration.

    Error message is below

    "Unable to determine the relationship represented by navigation property 'User.DeleterUser' of type 'User'. Either manually configure the relationship, or ignore this property from the model."

    P.S. I Include module zero (the current version)

    <span style="color:#FF0000">But</span>

    Pomelo.EntityFrameworkCore.MySql is work fine.

    after abpusertokens table created, then throw exception below.

    MySql.Data.MySqlClient.MySqlException: Specified key was too long; max key length is 767 bytes
       at MySql.Data.MySqlClient.MySqlDataReader.ActivateResultSet(ResultSet resultSet)
       at MySql.Data.MySqlClient.MySqlDataReader.<ReadFirstResultSetAsync>d__62.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at MySql.Data.MySqlClient.MySqlDataReader.<CreateAsync>d__61.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at MySql.Data.MySqlClient.CommandExecutors.TextCommandExecutor.<ExecuteReaderAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at MySql.Data.MySqlClient.CommandExecutors.TextCommandExecutor.<ExecuteNonQueryAsync>d__1.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
       at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.<ExecuteAsync>d__3.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlRelationalCommand.Execute(IRelationalConnection connection, String executeMethod, IReadOnlyDictionary`2 parameterValues, Boolean closeConnection)
       at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCommands, IRelationalConnection connection)
       at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
       at Abp.Zero.EntityFrameworkCore.AbpZeroDbMigrator`1.CreateOrMigrate(AbpTenantBase tenant, Action`1 seedAction)
       at MyGZ.Migrator.MultiTenantMigrateExecuter.Run(Boolean skipConnVerification) in E:\Users\jakeuj\Desktop\MyGZ\src\MyGZ.Migrator\MultiTenantMigrateExecuter.cs:line 63
    

    I think mysql not support Length: 2000 Value = table.Column

    migrationBuilder.CreateTable(
                    name: "AbpSettings",
                    columns: table => new
                    {
                        Id = table.Column&lt;long&gt;(nullable: false)
                            .Annotation("MySql:ValueGeneratedOnAdd", true),
                        CreationTime = table.Column&lt;DateTime&gt;(nullable: false),
                        CreatorUserId = table.Column&lt;long&gt;(nullable: true),
                        LastModificationTime = table.Column&lt;DateTime&gt;(nullable: true),
                        LastModifierUserId = table.Column&lt;long&gt;(nullable: true),
                        Name = table.Column&lt;string&gt;(maxLength: 256, nullable: false),
                        TenantId = table.Column&lt;int&gt;(nullable: true),
                        UserId = table.Column&lt;long&gt;(nullable: true),
                        Value = table.Column&lt;string&gt;(maxLength: 2000, nullable: true)
                    },
                    constraints: table =>
                    {
                        table.PrimaryKey("PK_AbpSettings", x => x.Id);
                        table.ForeignKey(
                            name: "FK_AbpSettings_AbpUsers_UserId",
                            column: x => x.UserId,
                            principalTable: "AbpUsers",
                            principalColumn: "Id",
                            onDelete: ReferentialAction.Restrict);
                    });