错误1“system.data.entity.db ... [英] Error 1 'system.data.entity.db...

查看:90
本文介绍了错误1“system.data.entity.db ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试使用MVC 5创建管理页面。我收到以下错误请帮我修复此错误。



错误1'System.Data.Entity.DbContext'不包含'角色'的定义..



我试图添加System.Data.Entity dll和命名空间但仍然显示错误。





谢谢你提前



我的尝试:



Hi,

I am trying to create a admin page using MVC 5. I am getting below error please help me to fix this error.

Error 1 'System.Data.Entity.DbContext' does not contain a definition for 'Roles'..

I have tried to add System.Data.Entity dll and namespace but still it's showing error.


Thank You in Advance

What I have tried:

public class RoleController : Controller
    {
        // GET: Role

        public ActionResult Role()
        {
            if (User.Identity.IsAuthenticated)
            {
                if (!isAdminUser())
                {
                    return RedirectToAction("Index", "Home");
                }
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
            
             var Roles = DbContext.Roles.ToList(); // Here I am getting error on Roles
            
            return View(Roles);
        }
        
        private bool isAdminUser()
        {
            if (User.Identity.IsAuthenticated)
            {
                var user = User.Identity;
                ApplicationDbContext DbContext = new ApplicationDbContext();
                var UserManager = new UserManager<applicationuser>(new UserStore<applicationuser>(DbContext));
                var s = UserManager.GetRoles(user.GetUserId());
                if (s[0].ToString() == "Admin")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            return false;            
        //    //throw new NotImplementedException();
        }
}

推荐答案

引用:

我有试图添加System.Data.Entity dll和命名空间,但仍然显示错误。

I have tried to add System.Data.Entity dll and namespace but still it's showing error.



尝试阅读并理解错误消息怎么样?

随机更改很少解决问题,你有一个明确的错误信息利用它。



如果没有数据库结构,给你提供更好的建议会很复杂。


What about trying to read and understand the error message ?
Random changes rarely solve problem, you have a clear error message take advantage of it.

Without db structure, it will be complicated to give you better advice.


这篇关于错误1“system.data.entity.db ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆