Metadata file not found – Data.Entity.Model

Based on C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS.ttinclude , the code generator is looking for the missing DLLs in the following locations: <#@ assembly name=”%VS120COMNTOOLS%..\IDE\EntityFramework.dll” #> <#@ assembly name=”%VS120COMNTOOLS%..\IDE\Microsoft.Data.Entity.Design.dll” #> I discovered that the environment variable %VS120COMNTOOLS% is not compatible with the correct installation path of visual studio, so I changed it from … Read more

Using SimpleMembership with EF model-first

SimpleMembership can work with model first. Here is the solution. 1.InitializeSimpleMembershipAttribute.cs from MVC 4 Internet Application templete should look like this namespace WebAndAPILayer.Filters { [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public sealed class InitializeSimpleMembershipAttribute : ActionFilterAttribute { private static SimpleMembershipInitializer _initializer; private static object _initializerLock = new object(); private static bool _isInitialized; … Read more

Using the Entry().CurrentValues.SetValues() is not updating collections

SetValues never updates navigation properties. When you execute your code it only knows about changes in simple / complex properties of the entity passed to your Update method. EF even don’t know about related entities of the entity passed to your Update method. You must manually tell EF about each change in your object graph … Read more

Entity Framework Validation confusion – maximum string length of ‘128’

Default length of string field in code first is 128. If you are using EF validation it will throw exception. You can extend the size by using: [StringLength(Int32.MaxValue)] public string Body { get; set; } This post became somehow popular so I’m adding second approach which also works: [MaxLength] public string Body { get; set; … 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