Using Entity Framework Code First CTP5, how do I create a primary key column that are INTs and are not identity columns

That answer didn’t work for me (in EF 4.1). To make this work, I added DatabaseGenerated attribute to my key column: public class FacebookUser { [Key] [DatabaseGenerated(DatabaseGeneratedOption.None)] public long FacebookId { get; set; } // … } Hope this helps someone.

Nested DbContext due to method calls – Entity Framework

Your DbContext derived class is actually managing at least three things for you here: the metadata that describes your database and your entity model, the underlying database connection, and a client side “cache” of entities loaded using the context, for change tracking, relationship fixup, etc. (Note that although I term this a “cache” for want … Read more

The type ‘Company.Model.User’ and the type ‘Company.Core.Model.User’ both have the same simple name of ‘User’ and so cannot be used in the same model

This is a limitation of EF that I reported in 2012 https://entityframework.codeplex.com/workitem/483 that is still not implemented in 6.0.2. EF uses a flat internal architecture and does not recognize namespaces. Might be coming in EF7 but not before. For now the only solutions is to rename the two classes to unique class names irrespective of … Read more

DbContextTransaction Rollback

No it is not necessary to explicitly call Rollback. The tx variable will be disposed when the using block finishes, and the transaction will be rolled-back if Commit() has not been called. I have tested this using SQL Server Activity Monitor, by observing the locks held on the database objects, as well as querying against … Read more

AutomaticMigrationsEnabled false or true?

Automatic migrations do all the magic for you but they don’t allow strict versioning (you don’t have special fixed migration for each version). Without strict versioning you cannot track version of your database and you cannot do explicit upgrades (you cannot do downgrades at all). If you don’t plan to use versioning where you need … Read more

No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlServerCe.4.0’

After installing the EntityFramework.SqlServerCompact nuget package, check that your app.config contains the following (as per @ErikEJ’s comment above): <providers> <provider invariantName=”System.Data.SqlClient” type=”System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer” /> <provider invariantName=”System.Data.SqlServerCe.4.0″ type=”System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact” /> </providers> (You can leave the line for SqlClient even though you don’t really need it.)

Entity Framework Code First Using Guid as Identity with another Identity Column

This ended up working for me, Entity Framework 5. Turn off automatic migrations Migrate to create the initial table, no frills Declare the ClusterId as Identity (annotation) [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override int ClusterId { get; set; } Migrate Declare the pk property Id as Identity after the other one has been updated [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public override Guid … Read more