Recently i upgraded from EF5 to EF6 and here is list of items which one needs to take care of
EF MiniProfiling: if you were using mini profiling with EF5 you will have broken code as few of the functiionality or variable names had been changed.
Resolution: Upgrade to newer version of EF MiniProfiling
Db-Reindexing: After updating to EF6 it complaints you about change in your model and when you do "Add-Migration" you will see all your index for primary key were getting recreated also its changing name of tables where you have one to one relationship so previously if it generates table name as TableATableB then it will rename table as TableBTableA dont know why.
Resolution 1: Let EF create migrations for create index , just comment out line in
up and down function.
Resolution 2: Copy line of code from down function(i.e. drop index) and try to execute it before it create index , simple rule first drop and then create, you need this else EF will complaint about index already present.
Migrations: This will only affect you if you are doing using some tool to deploy you assemblies and which in turns uses migrate.exe typically found at
...#your project location\packages\EntityFramework.6.1.0\tools\migrate.exe
copy it to your bin folder and things should work fine.
4. Null Handling: In EF6 handling of null values had been changed , my hands on experience says that with ef5 select query was ignoring null cases but is not the case with ef6
e.g. if i have query something like
db.context.entity.where(name != "ab");
and lets say entity table contains two names {"ab",null}
with EF5 it will return 1 row with ef6 it was returning 2 rows
http://entityframework.codeplex.com/workitem/2115
Resolution: If you wanted to work exactly like EF5 you can set
dbContext.Configuration.UseDatabaseNullSemantics = true;
If it helps please don't forgot to mark this post as answered :)
Related
I am working on a new application in .Net 5 using EF Core. After creating some entity classes and doing the first few migrations I discovered that I wanted to change the data type of column and make it the key in one of the tables. I was able to do that without issue and the app works just fine with that change - but now if I try to change anything else in that table like add a new column and do a migration I get the following error: "To change the IDENTITY property of a column, the column needs to be dropped and recreated." I have tried even dropping the entire table - but nothing seems to work.
Whenever your migrations get messed up, especially early in a project, just delete the migrations folder, drop the Migration History table and start fresh with a new initial migration.
I'm using Database First approach and I have table called Campus and when I add to my edmx from SQL Server and I see that it renamed to Campu why is that doing?
I'm guessing that your project is having some table pluralization problems. So when your table Campus is created, Entity Framework is literally reading it as an entity called a Campu that you have pluralized to be Campus.
See this link on how to change pluralization.
But this isn't really a problem right? You can change your model name back to Campus.
This is a really weird error, I have looked online and can not see any obvious reasons why this is happening.
I am using Database First Entity Framework version 5 and have added 4 tables called:
WorkStatus
JobStatus
SubJobStatus
SubJobStageStatus
JobStatus, SubJobStatus and SubJobStageStatus each has a foreign key constraint to WorkStatus.
I have updated my edmx to include these tables but for some reason each table is missing the last s from the word Status. So the tables and their navigation properties are now called:
WorkStatu
JobStatu
SubJobStatu
SubJobStageStatu
Does anyone know why this happens?
"-Status" is being interpreted as a plural, and Entity Framework is being "helpful" by de-pluralizing.
For example, if you have a table called "Customers" EF will generate an entity called "Customer", which is in fact nicer in code:
var customer = new Customer();
It isn't working out so well in your case; your tables are already singular.
You can rename your tables to "-Statuses" or update the names in the designer or disable pluralization:
Under Tools > Options
I am using Entity Framework 5 RC, code first. I am struggling with migrating databases that were created on different versions of code. For example, Database A was created when table FooBar didn't exist. Database B was created after table FooBar was added to my model.
I have a migration written that adds the FooBar table. Is it my responsibility to check in the FooBar migration that the table doesn't exist before calling CreateTable? It seems that is the case since Database B doesn't have an entry for the FooBar migration and will attempt to run it.
At first the MigrationHistory table seemed like it would save me from adding these checks but since new databases won't have entries for migrations added before the database was created, I still need to do the checks myself. Is that the right way to go about it or am I missing something?
To get around an issue I had with adding Stored Procedures, I wrote a TSQL script to create a new table "_PreviousMigrationHistory" - which receives new entries from the "_MigrationHistory" table after my stored procedure scripts have run...
I did add a new column to both tables ( "VersionId", of INT - IDENTITY(1,1) ) which is what I use for comparison within my code.
This way you have the un-updated migration patterns available to you (__PreviousMigrationHistory), even after Code First Migrations have occurred.
Would this help?
**EDIT - sorry, I miss read the question. - Although I would think that new instances of the database would still go through the migration steps, which in turn should add the entries to the __MigrationHistory table?
I'm giving EF Model first a go. I'm using EF 4.1
Pretty much followed this article
I've set PluraliseNewObjects to False on the Model and also in Options->Database Tools ->O/R Designer set Pluralization of names to false.
Neither have any effect - when I generate a new schema from the model the table names are always pluralised - is it possible to disable this?
OK - I've found one way to achieve what I want - but it's a pretty daft route.
Generated db with the plural names (interesting that it only pluralised the tables mapping to types - not the auto-generated linking tables for many to many joins).
Manually renamed the tables in the database
Deleted Model from the project and recreated based on existing database schema (the one I've just renamed).
Model is now correctly mapped to singularly names tables.
I'll wait and see if anyone comes up with a more sensible way of achieving this....
The names of the tables in the generated DDL seem to match the "Entity Set Name" values (different than the "Entity Name"). If you singularize the Entity Set Names, the table names in the DDL are singularized as well.
This will have the possibly undesired effect of singularizing the EntitySet property names in your code, though. Instead of:
myDatabase
.Products
.Where...
.Select...
your code will look like:
myDatabase
.Product
.Where...
.Select...
may or may not be an issue