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

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: One Database, Multiple DbContexts. Is this a bad idea? [closed]

Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago. Improve this question My impression to date has been that a DbContext is meant to represent your database, and … Read more

Unique Key constraints for multiple columns in Entity Framework

I’m using Entity Framework 5.0 Code First; public class Entity { [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] public string EntityId { get; set;} public int FirstColumn { get; set;} public int SecondColumn { get; set;} } I want to make the combination between FirstColumn and SecondColumn as unique. Example: Id FirstColumn SecondColumn 1 1 1 = OK 2 2 … Read more

Create code first, many to many, with additional fields in association table

I have this scenario: public class Member { public int MemberID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public virtual ICollection<Comment> Comments { get; set; } } public class Comment { public int CommentID { get; set; } public string Message { get; set; … 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

Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths – why?

I’ve been wrestling with this for a while and can’t quite figure out what’s happening. I have a Card entity which contains Sides (usually 2) – and both Cards and Sides have a Stage. I’m using EF Codefirst migrations and the migrations are failing with this error: Introducing FOREIGN KEY constraint ‘FK_dbo.Sides_dbo.Cards_CardId’ on table ‘Sides’ … 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