I am using ASP.NET Identity 2 with EF. In ASP.NET Identity I have PhoneNumber property which in my case(business wise) is mobile-number. But I also have Phone-Number which I am using for as office-phone. Now I want all my code use MobileNumber(for mobile) and PhoneNumber(for office). I can do something like this, How can I change the table names when using Visual Studio 2013 ASP.NET Identity? But in that case I need to change the property name. I want to change the property name as well as database column name.
Asked
Active
Viewed 202 times
2 Answers
2
Just rename property on your class. Create a EF migration. Most likely it will drop existing column you are trying to rename and add a new column. Replace that migration code with RenameColumn("dbo.MyTableName", "OldColumnName", "NewColumnName");

trailmax
- 34,305
- 22
- 140
- 234
-
The problem is that this property is used by the framework. I can change in DB but not in class. – Imran Qadir Baksh - Baloch Sep 01 '15 at 15:40
-
how? How the framework knows that he has to use MobileNumber property instead of PhoneNumber? Remember that its define in base identity class. – Imran Qadir Baksh - Baloch Sep 01 '15 at 16:04
-
Oh, did not realise you are talking about property on `IdentityUser`. I would inherit `IdentityUser` and add a new properties on the inherited class - whichever ones you need. And don't bother with the inbuilt `PhoneNumber` – trailmax Sep 01 '15 at 21:19
2
You can inherit your model from IdentityUser class and add new property to it
public class User : IdentityUser
{
public string MobileNumber { get; set; }
}
and for renaming column in database use this code
protected override void OnModelCreating(DbModelBuilder builder)
{
builder.Entity<User>()
.Property(u => u.PhoneNumber)
.HasColumnName("NewName");
}

Arash
- 889
- 7
- 18