文章内容

2017/7/28 9:31:35,作 者: 黄兵

The entity type Blog is not part of the model for the current context.

今天在写代码的时候报如下错误:

The entity type Blog is not part of the model for the current context.

截图如下:

代码如下:

using System.Data.Entity;
using AppDAL.Entity;

namespace AppDAL.Model
{
    public class AppContext:DbContext
    {
        public AppContext()
            : base("name=BlogAppConn")
        { }

        
    }
}
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace AppDAL.Entity
{
    public partial class Blog
    {       
        public int Id { get; set; }

        [Required]
        [StringLength(500)]
        [DisplayName("标题")]
        public string Title { get; set; }

        [Required]
        [DisplayName("正文")]
        public string Body { get; set; }
        [DisplayName("创建时间")]
        public DateTime CreationTime { get; set; }
        [DisplayName("更新时间")]
        public DateTime UpdateTime { get; set; }
        [DisplayName("选择类别")]
        public int CategoryId { get; set; }
        [DisplayName("作者")]
        public int AuthorId { get; set; }
        public int ArchivesId { get; set; }
        [DisplayName("专题页面")]
        public bool Topics { get; set; }
    }
}

解决方案:

using System.Data.Entity;
using AppDAL.Entity;

namespace AppDAL.Model
{
    public class AppContext:DbContext
    {
        public AppContext()
            : base("name=BlogAppConn")
        { }

        public DbSet<Blog> Blogs { get; set; }
    }
}

参考资料:EntitySet System.InvalidOperationException - “the entity type is not part of the model for the current context”

黄兵个人博客原创。

转载请注明出处:黄兵的个人博客 - The entity type Blog is not part of the model for the current context.

分享到:

发表评论

评论列表