Getting exact error type in from DbValidationException

I have the situation where I’m initializing my model in DatabaseInitializer() for EF 4.1 and get this annoying error “Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details.” So, I go to this EntityValidationErrors and there is a field {System.Data.Entity.Validation.DbEntityValidationResult} which gives me no information at all about what field it … Read more

The relationship could not be changed because one or more of the foreign-key properties is non-nullable

I am getting this error when I GetById() on an entity and then set the collection of child entities to my new list which comes from the MVC view. The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a … Read more

How to pass parameters to the DbContext.Database.ExecuteSqlCommand method?

Let’s just suppose I have a valid need for directly executing a sql command in Entity Framework. I am having trouble figuring out how to use parameters in my sql statement. The following example (not my real example) doesn’t work. var firstName = “John”; var id = 12; var sql = @”Update [User] SET FirstName … Read more

What effect(s) can the virtual keyword have in Entity Framework 4.1 POCO Code First?

Does the virtual keyword has an effect when used on the properties in EF Code First?. Can someone describe all of its ramifications in different situations? For instance, I know it can control lazy loading — if you use the virtual keyword on an ICollection/one-to-many relationship property, it will be lazy-loaded by default, whereas if … Read more

Entity Framework Code First – two Foreign Keys from same table

I’ve just started using EF code first, so I’m a total beginner in this topic. I wanted to create relations between Teams and Matches: 1 match = 2 teams (home, guest) and result. I thought it’s easy to create such a model, so I started coding: public class Team { [Key] public int TeamId { … Read more

Ignoring a class property in Entity Framework 4.1 Code First

My understanding is that the [NotMapped] attribute is not available until EF 5 which is currently in CTP so we cannot use it in production. How can I mark properties in EF 4.1 to be ignored? UPDATE: I noticed something else strange. I got the [NotMapped] attribute to work but for some reason, EF 4.1 … Read more

Code-first vs Model/Database-first [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question What are the pros & cons of using Entity Framework 4.1 Code-first over Model/Database-first with … Read more

Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details [duplicate]

This question already has answers here: Getting exact error type in from DbValidationException (7 answers) Closed 1 year ago. I am having this error when seeding my database with code first approach. Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details. To be honest I don’t know how to check the … Read more