奇怪的错误:当播种实体数据库时,类型名称'Models'在类型....中不存在

时间:2016-03-18 23:45:22

标签: c# asp.net-mvc entity-framework

尝试将初始种子设置到我的实体数据库时,我收到了一个奇怪的引用错误。 The type name 'Models' does not exist in the type 'SetupSheet.Models.SetupSheet'我无法弄明白。我必须有这些参考文献:

using SetupSheet.Models;
using SetupSheet.Models.CollectionofTool;

用于TurningTool对象的定义属性。

Error

Configuration.cs

namespace SetupSheet.Migrations
{
    using SetupSheet.Models;
    using SetupSheet.Models.CollectionofTool;
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;

    internal sealed class Configuration : DbMigrationsConfiguration<SetupSheet.Models.DataModel>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = true;
        }

        protected override void Seed(SetupSheet.Models.DataModel context)
        {
            context.TurningTools.AddOrUpdate(
                t => t.TurningToolShape,
                new TurningTool { Id = 1, InsertRadius = .032, TurningToolShape = TurningToolShape.Diamond, CreationDate = DateTime.Now },
                new TurningTool { Id = 2, InsertRadius = .064, TurningToolShape = TurningToolShape.Triangle, CreationDate = DateTime.Now },
                new TurningTool { Id = 3, InsertRadius = .125, TurningToolShape = TurningToolShape.Diamond, CreationDate = DateTime.Now }

             );

        }
    }
}

TurningTool.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace SetupSheet.Models.CollectionofTool
{
    public class TurningTool : Tool
    {
        [Required]
        [Display(Name = "Turning Tool Shape")]
        [Index("XI_TurningToolShape_Radius_Grade", 1, IsUnique = true)]
        public TurningToolShape TurningToolShape { get; set; }

        [Required]
        [Display(Name = "Insert Radius")]
        [Index("XI_TurngingToolShape_Radius_Grade", 2, IsUnique = true)]
        public double InsertRadius { get; set; }

    }
}

Tool.cs

using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace SetupSheet.Models
{
    public class Tool
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int Id { get; set; }

        [Required]
        [Display(Name = "Type of Tool")]
        public ToolType? ToolType { get; set; }

        public string Description { get; set; }

        [Display(Name = "Creation Date")]
        [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
        public DateTime CreationDate { get; set; }
        [Required]
        [Index("XI_TurningToolShape_Radius_Grade", 3, IsUnique = true)]
        public Grade Grade { get; set; }    
    }

    public enum TurningToolShape
    {
        [Description("Diamond")]
        Diamond = 1,
        [Description("Triangle")]
        Triangle = 2
    }
}

1 个答案:

答案 0 :(得分:0)

是的,我有一个类型的SetupSheet。我改变了它,它不起作用。感谢Ivan Gritsenko。