In my model I have navigation property Language:
public class IntegratorDescription : BaseContract
{
[Key, Column(TypeName = "bigint"), DataMember]
public long Id { get; set; }
[DataMember, Column(TypeName = "bigint"), ForeignKey("Language")]
public long LangId { get; set; }
[DataMember]
public string CompanyShortInfo { get; set; }
[DataMember, Column(TypeName = "ntext")]
public string CompanyInfo { get; set; }
public virtual Models.Language Language { get; set; }
}
Language table already exists and it's done by another ORM, I need to say Migrations not to try to create Language table but update only Description table. How?
-"There is already an object named 'Languages' in the database."
Run the Add-Migration InitialCreate command in Package Manager Console. This creates a migration to create the existing schema. Comment out all code in the Up method of the newly created migration. This will allow us to 'apply' the migration to the local database without trying to recreate all the tables etc.
To use code-first for an existing database, right click on your project in Visual Studio -> Add -> New Item.. Select ADO.NET Entity Data Model in the Add New Item dialog box and specify the model name (this will be a context class name) and click on Add.
After creating a migration file using the add-migration command, you have to update the database. Execute the Update-Database command to create or modify a database schema. Use the –verbose option to view the SQL statements being applied to the target database.
-IGNORECHANGES
Scaffolds an empty migration ignoring any pending changes detected in the current model. This can be used to create an initial, empty migration to enable Migrations for an existing database. N.B. Doing this assumes that the target database schema is compatible with the current model.
http://coding.abel.nu/2012/03/ef-migrations-command-reference/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With