Answer the question
In order to leave comments, you need to log in
Migration and Fluent API. How to change the default name of the key property Id to something else when using fluent api and magicia?
Hello.
I decided to try Fluent api in Entity Framework.
I'm trying to change the name of the key property of a simple model class from the standard Id to Ident in order to set a new key name with the
modelBuilder.Entity().HasKey(p => new { p.Ident, p.Name });
However, after changing the property name in the Phone class from Id to Ident, as shown below
public class Phone
{
// public int Id { get; set; }
public int Ident { get; set; }
public string Name { get; set; }
public int Price { get; set; }
}
The environment requires the use of migration, because model has been changed.
However, during the migration, after the update-database command, an error appears in the console: "Multiple identity columns are specified for the 'Phones' table. Only one identity column is allowed per table."
When using other Fluent Api rules, say ignoring some property, the migration works fine.
What can be done here, well, besides initially using Fluetn api on a "fresh" model?
Small console project code with this error: https://github.com/Alexis1784/question.git
Used .net 4.5 and latest version of EF.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question