Identityserver4.admin: Extend Client for new column in database

Created on 26 Oct 2020  路  4Comments  路  Source: skoruba/IdentityServer4.Admin

Question

hi dear,
I am implementing a new feature and want to update the client table with a new column the dto is worked fine but at auto mapper is the problem how could i make it happen

Relevant parts of the log file

Severity    Code    Description Project File    Line    Suppression State
Error   CS1503  Argument 1: cannot convert from 'Skoruba.IdentityServer4.Admin.BusinessLogic.Mappers.ClientExt' to 'IdentityServer4.EntityFramework.Entities.Client'    Skoruba.IdentityServer4.Admin.BusinessLogic D:\Tasks\Identity\ID#TEST\identityservercore\Admin\src\Skoruba.IdentityServer4.Admin.BusinessLogic\Services\ClientService.cs    153 Active

   <log goes here>
question

Most helpful comment

Did you applied the migration on the database?
Is the Discriminator and the new property part of the table definition in SQL server?
If not, you have to apply the migration. To do that you have 2 possibilities:

  1. Run the seed command. This will update the db.
  2. In nuget package manager console in Vs you can execute this command: update-database -c ContextName // in your case it should be the configuration context. Make sure the project which contains the migrations is selected as startup proj.

Hope this would solve your issue.

All 4 comments

Hi, if you name the same your new property/column in both dto and entity then, the mapper should not be a problem.
What you have to do is to create a new Client class that inherits from Client class. eg.: public class ExtendedClient: Client

  • Change the DBSet to use ExtendedClient in IAdminConfigurationDbContext
  • Update ClientRepository to use the new type.
  • In the generated migration make sure the default value is added:
migrationBuilder.AddColumn<string>(
                name: "Discriminator",
                table: "Clients",
                nullable: false,
               defaultValue: "ExtendedClient");
  • And fix all references.

Pretty much these were the changes we've done to extended the client definition with new properties.

@mitirazvan thanx for your answer i really appreciate it. but now i got this
`MySqlException: Unknown column 'x.Discriminator' in 'field list'

MySqlConnector.Core.ServerSession.TryAsyncContinuation(Task> task) in ServerSession.cs, line 1252`

Did you applied the migration on the database?
Is the Discriminator and the new property part of the table definition in SQL server?
If not, you have to apply the migration. To do that you have 2 possibilities:

  1. Run the seed command. This will update the db.
  2. In nuget package manager console in Vs you can execute this command: update-database -c ContextName // in your case it should be the configuration context. Make sure the project which contains the migrations is selected as startup proj.

Hope this would solve your issue.

things work now thanx @mitirazvan

Was this page helpful?
0 / 5 - 0 ratings

Related issues

knepe picture knepe  路  4Comments

Aegide picture Aegide  路  4Comments

imabdul-dev picture imabdul-dev  路  4Comments

woeterman94 picture woeterman94  路  4Comments

Mehrdad-Davoudi picture Mehrdad-Davoudi  路  4Comments