-3

As you know Boilerplate don't give the entity classes to add columns and I want to add column in table named ( AbpUser). I tried to make a class in Migrations like below

public partial class AddRatingMig : DbMigration
{
    public override void Up()
    {
        AddColumn("dbo.AbpUsers", "UserType", c => c.String());
    }

    public override void Down()
    {
        DropColumn("dbo.AbpUsers", "UserType");
    }
}

Then in Pm console run command Update-Database . But not successful. As you know Boilerplate don't give the entity classes to edit columns. Please Help Thanks in advance

Mesam Mujtaba
  • 114
  • 12
  • Please read [ask] and learn about what is on-topic to ask here. Your question is very broad. It is expected that you've already made an attempt at solving your problem before asking here. I would look at some tutorials online and then if you have trouble implementing it, come back here and ask a more specific question with a [mcve], – Lexi Aug 24 '17 at 12:43
  • I asked a simple question. Its about a specific framework, if you know about Boilerplate framework then guide please... – Mesam Mujtaba Aug 24 '17 at 12:46
  • You did not ask a question that is within the guidelines on this site. If you read through the [help], you would have been aware of that. – Lexi Aug 24 '17 at 12:46
  • Then you aren't likely to get an answer. If you aren't going to take the time to write a good question, why should a volunteer take the time to write a good answer to an off-topic question? – Lexi Aug 24 '17 at 12:49
  • Check now @Lexi . I am not good in English but tried to explain my problem – Mesam Mujtaba Aug 24 '17 at 12:59
  • The answer to this question is to Extend the AbpUser like this public class User : AbpUser { public string SpecialTitle { get; set; } } – Vince Aug 24 '17 at 16:55
  • Ok let me check – Mesam Mujtaba Aug 25 '17 at 05:22
  • @Vince I did all which you are telling.. But got an error on running in browser – Mesam Mujtaba Aug 25 '17 at 05:31
  • Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed. – Mesam Mujtaba Aug 25 '17 at 05:31
  • @Vince after enabling Migrations and updating database. I found solution. Thanks man. Please write your above answer in answer pane so i can mark it true. Thanks again – Mesam Mujtaba Aug 25 '17 at 05:44
  • there is no restriction to extend the user class. you can extend it by inheriting. [Table("AbpTenants")] public class MyUser : User { } – Alper Ebicoglu Aug 25 '17 at 06:12
  • please read the document. it's explained very good in docs. https://aspnetboilerplate.com/Pages/Documents/Zero/installation?searchKey=user – Alper Ebicoglu Aug 25 '17 at 06:13
  • Yes i got that. thanks anyway – Mesam Mujtaba Aug 25 '17 at 06:39

3 Answers3

5

The answer to this question is to Extend the AbpUser like this

public class User : AbpUser<User> 
{ 
    public string SpecialTitle { get; set; } 
}

and add-migration UpdatedUserWithSpecialTitle then update-database

Vince
  • 1,279
  • 2
  • 20
  • 40
0

Here is the correct way

public partial class AddRatingMig : DbMigration
 {
    public override void Up(MigrationBuilder migrationBuilder)
  {
    migrationBuilder.AddColumn<string>(
      name: "UserType",
      table:"AbpUsers",
      nullable:true
      );
  }

    public override void Down(MigrationBuilder migrationBuilder)
      {
        migrationBuilder.DropColumn(
        name:"UserType",
        table:"dbo.AbpUsers"
        );
      }
}

Hence update Database using code as: update-database

NOTE:

Make sure that you have properly added migrations as: add-migration migration_name

James Z
  • 12,209
  • 10
  • 24
  • 44
0

I had the same problem in abp.io framework, adding new property, "PICUstomerId" to AbpUser Entity and migrate it to database.

Here is the comments by abp.io:

Add your own properties here. Example:

public string MyProperty { get; set; }
If you add a property and using the EF Core, remember these;

  1. Update PasargadInsuranceDbContext.OnModelCreating to configure the mapping for your new property
  2. Update PasargadInsuranceEfCoreEntityExtensionMappings to extend the IdentityUser entity and add your new property to the migration.
  3. Use the Add-Migration to add a new database migration.
  4. Run the .DbMigrator project (or use the Update-Database command) to apply schema change to the database.

and finally add-migration to your solution and then update-database

1. Add your own properties here

2. Update PasargadInsuranceDbContext.OnModelCreating

3. Update PasargadInsuranceEfCoreEntityExtensionMappings to extend theIdentityUser entity

4. And finally after update-databse, I saw my new property in database