相关疑难解决方法(0)

一个或多个实体的验证失败.有关详细信息,请参阅"EntityValidationErrors"属性

我在使用代码优先方法播种数据库时遇到此错误.

一个或多个实体的验证失败.有关详细信息,请参阅"EntityValidationErrors"属性.

说实话,我不知道如何检查验证错误的内容.Visual Studio向我显示它是一个包含8个对象的数组,因此有8个验证错误.

这与我之前的模型有关,但我做了一些修改,我在下面解释:

  • 我有一个名为Status的枚举,我将其更改为名为Status的类
  • 我将类ApplicantsPositionHistory更改为在同一个表中有2个外键

请原谅我的长代码,但我必须将其全部粘贴.在以下代码的最后一行中抛出异常.

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)

c# entity-framework entity-framework-4 entity-framework-4.1

767
推荐指数
19
解决办法
68万
查看次数

调试代码优先的Entity Framework迁移代码

我首先在我的网站上使用实体框架代码,我只是想知道是否有任何方法来调试迁移代码.你知道,比如设置断点和类似的东西.

我正在使用Package Manager Console使用update-database更新数据库.

谢谢

entity-framework ef-code-first ef-migrations entity-framework-5

131
推荐指数
5
解决办法
4万
查看次数

MVC实体框架中的种子方法

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)

c# asp.net asp.net-mvc entity-framework asp.net-mvc-3

7
推荐指数
1
解决办法
1万
查看次数