I am reading through the book EF Code First by Julie Lerman. In the book, a database is created which contains tables generated from the domain model, as well a table named edmmetadatatable. Apparently, this table is needed for checking if there are any changes made to the other tables.
But, I don't have it. And I don't know how to get it.
One thing I did differently from the book was that I added my own connection string since code first defaults for SQLEXPRESS and I don't have SQLEXPRESS.
The book is covering Entity Framework 4.2 which uses the EdmMetadata table. When migrations were introduced in EF 4.3, a __MigrationHistory table was introduced instead.
See here for more information.
Related
We've been using flyway for schema migrations, versions 4.x/5.x - the table is named schema_version. Now we are looking to move to latest version, 7.x. I've seen some information that states the new table name has changed to flyway_schema_history, but then I just saw this where the table name looks to be named flyway_history_schema (https://flywaydb.org/documentation/concepts/migrations#schema-history-table).
Can anyone who uses flyway confirm the schema history table name?
Thanks,
Scott
The default name for the table is indeed flyway_schema_history
The part of the documentation you linked to is referring to the situation when Flyway is not allowed to create new schemas by its configuration, and you need to manually create a schema for that table to live in. "flyway_history_schema" is a suggested name for the schema, not the table.
I have several tables with columns referencing the standard
asp.net core AspNetUsers Column. That worked without problems, but now i added a new Table and all over sudden I get an error when trying to add my new table:
Column 'xyz.AspNetUsers.Id' is not of same collation as
referencing column 'Device.LastModifiedById' in foreign key
'FK_Device_AspNetUsers_LastModifiedById'.
Everything is created code-first with EntityFrameworkCore 1.1.1 (Tools 1.1.0), execept a different schema (modelBuilder.HasDefaultSchema("xyz") I use all standard-values, and did not change anything with Collations.
Has somebody had a similar issue? Thanks in advance!
Narf, turned out I had restored my DEV-Database earlier from Production-Database... and simply missed selecting the proper Collation as Database-Default.
I am using asp.net 4.5 with EF to add/update/delete record.
I renamed a database table StatusMaster to Status.
To reflect this change in entity, I have used "update model from database" in which I have deleted the table first.
Then I have deleted the table from the diagram using "Delete Model".
Then I added table to the edmx file using "Update Model from Database".
I also have update related code in application.
Now Add() method is working well but while update method it gives me error "Invalid column name 'Id'". This column was the primary key before I update but I have also renamed it to "StatusId" but I don't think it should affect it because I already have deleted and added the table using "Update model from database".
Please help me.
All the more reason I prefer code first. More work to set up but easier to make changes down the line. Ill suggest you do the following.
Delete the entire EDMX
Delete Connection Details from config section in Web.config
Re-Create EDMX
I discovered that is faster that trying to debug ur relationship in the EDMX diagram
I'm learning migrations and I'm curious how migration tool figures out which changes to our model were made after the last migration was created.
For example, assume we created a migration M1 and apply it by issuing command Update-Database. After applying M1, if we add a new property P to a class C and create another migration M2 by issuing command Add-Migration M2, then migration tool will somehow be able to figure out that only change ( after M1 was created ) we made to the model was adding a new property P to class C. How does migration tool figure that out?
thank you
REPLY:
Migrations uses __Migrations table to figure which migrations have already been applied and which have yet to be applied, but I thought it doesn't use this table to also figure out what changed from one migration to another, since data in migrations table is a hash, which means it can't be decrypted, which I assume would be necessary so that current model metadata can be compared with latest metadata stored in the migrations table?!
Or are you implying that it is able to figure out just by comparing hash values ( of current and stored versions ) which properties have changed or were deleted or were added to an entity?
It stores your model versions in the database (migrations history table) and compares your current model with the model stored in your database.
The model is stored in .resx file under each mifration in the Target resource value. It is an encoded (serialized) model. It is used to compare your current model and generate the next migration.
Can someone help me answer these questions on EntityFramework?
Does it do anything special to the database? (like extra tables)
Can I add data directly with SQL without breaking EF?
Can I add tables and fields without breaking EF?
Yes you can access database with plain SQL when using EF.
No. EF just uses database. There is one exception in code first approach where EF can create one additional table for its own purpose called EdmMetadata.
Yes you can add data directly with SQL. If both your entity model and database are defined correctly it will not break EF.
Yes you can add new tables directly but EF will not know about them. You should not change existing tables because it can break EF.
You can do it with:
var context = new YourObjectContext();
var s = context.ExecuteStoreCommand("some query");
if your query create a table, this only create a table on db and not effected on EF