CodeFirst EF4.1 MVC Against legacy database - Multiplicity conflicts

前端 未结 4 1300
闹比i
闹比i 2020-12-13 17:18

No matter which way I mix it, it gives me errors. I have a feeling I\'m missing something obvious as I keep getting these errors.

One or more validation

4条回答
  •  情歌与酒
    2020-12-13 17:48

    Hope this is still on time to help you. I was also having the exact same problem and was troubling with it for almost an hour until I could spot my mistake.

    The problem is that Course.Venue relationship is optional (as declared on the fluent API), but the Id declaration of Course.VenueId is mandatory, so you can either make VenueId optional by changing it to

    public int? VenueId { get; set;}
    

    or change the relationship to mandatory on the fluent API, and the OnModelCreating should run fine once you changed that.

提交回复
热议问题