我在使用代码优先方法播种数据库时遇到此错误.
一个或多个实体的验证失败.有关详细信息,请参阅"EntityValidationErrors"属性.
说实话,我不知道如何检查验证错误的内容.Visual Studio向我显示它是一个包含8个对象的数组,因此有8个验证错误.
这与我之前的模型有关,但我做了一些修改,我在下面解释:
请原谅我的长代码,但我必须将其全部粘贴.在以下代码的最后一行中抛出异常.
namespace Data.Model
{
public class Position
{
[DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGeneratedOption.Identity)]
public int PositionID { get; set; }
[Required(ErrorMessage = "Position name is required.")]
[StringLength(20, MinimumLength = 3, ErrorMessage = "Name should not be longer than 20 characters.")]
[Display(Name = "Position name")]
public string name { get; set; }
[Required(ErrorMessage = "Number of years is required")]
[Display(Name = "Number of years")]
public int yearsExperienceRequired { get; set; }
public virtual ICollection<ApplicantPosition> applicantPosition { get; set; …Run Code Online (Sandbox Code Playgroud) 我首先在我的网站上使用实体框架代码,我只是想知道是否有任何方法来调试迁移代码.你知道,比如设置断点和类似的东西.
我正在使用Package Manager Console使用update-database更新数据库.
谢谢
entity-framework ef-code-first ef-migrations entity-framework-5
seed method我的应用程序的迁移文件夹中的主要用途是什么?在我的Configuration.cs文件中,我在种子方法中得到了这个 -
protected override void Seed(TestApplication.DataBaseContext.AppDBContext context)
{
// This method will be called after migrating to the latest version.
// You can use the DbSet<T>.AddOrUpdate() helper extension method
// to avoid creating duplicate seed data. E.g.
//
// context.People.AddOrUpdate(
// p => p.FullName,
// new Person { FullName = "Andrew Peters" },
// new Person { FullName = "Brice Lambson" },
// new Person { FullName = "Rowan Miller" }
// );
//
SeedMemebership();
} …Run Code Online (Sandbox Code Playgroud)