Can you create sql views / stored procedure using Entity Framework 4.1 Code first approach

We support stored procedures in our Entity Framework Code First Migrations. Our approach is to create some folder to hold the .sql files (~/Sql/ for example). Create .sql files in the folder for both creating and dropping the stored procedure. E.g. Create_sp_DoSomething.sql and Drop_sp_DoSomething. Because the SQL runs in a batch and CREATE PROCEDURE.. must … Read more

How to configure ProviderManifestToken for EF Code First

If you’re using EF 6 (just released) you have an alternative. Dependency Resolution You can use the new dependency resolution feature to register an implementation of IManifestTokenResolver (described in this preview documentation as IManifestTokenService). This article gives a bit more information on how to use DbConfiguration. The easiest way to use it is like this: … Read more

Does Entity Framework Code First support stored procedures?

EDIT: My original answer for EF4.1 (below) is now out of date. Please see the answer below from Diego Vega (who works on the EF team at Microsoft)! @gsharp and Shawn Mclean: Where are you getting this information? Don’t you still have access to the underlying ObjectContext? IEnumerable<Customer> customers = ((IObjectContextAdapter)this) .ObjectContext.ExecuteStoreQuery<Customer>(“select * from customers”); … Read more

Entity Framework DateTime and UTC

Here is one approach you might consider: First, define this following attribute: [AttributeUsage(AttributeTargets.Property)] public class DateTimeKindAttribute : Attribute { private readonly DateTimeKind _kind; public DateTimeKindAttribute(DateTimeKind kind) { _kind = kind; } public DateTimeKind Kind { get { return _kind; } } public static void Apply(object entity) { if (entity == null) return; var properties = … Read more

ASP.NET MVC3 and Entity Framework Code first architecture

If you want to use TDD (or any other testing approach with high test coverage) and EF together you must write integration or end-to-end tests. The problem here is that any approach with mocking either context or repository just creates test which can test your upper layer logic (which uses those mocks) but not your … Read more

Validation failed for one or more entities while saving changes to SQL Server Database using Entity Framework

You can extract all the information from the DbEntityValidationException with the following code (you need to add the namespaces: System.Data.Entity.Validation and System.Diagnostics to your using list): catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation(“Property: {0} Error: {1}”, validationError.PropertyName, validationError.ErrorMessage); } } }