SimpleMembership中的用户列表返回空

时间:2015-11-16 16:18:03

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

编辑 - 我得到了它的工作。我曾为我的用户类创建了一个单独的上下文和viewmodel。我将所有内容都移动到与我的其他实体相同的模型/上下文/视图模型中,并且它可以工作。

我是简单会员的新手,我正试图从aspnetusers表中获取用户列表。目的是管理这些用户 - 设置角色等。我的代码运行,但查询返回空,尽管数据库中有用户。

我的背景......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using userModel;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;

namespace tvc.DAL
{
    public class usersContext : DbContext
    {
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);


d.creation_Date).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            modelBuilder.Entity<AspNetUser>().HasKey(e => e.Id);
            modelBuilder.Entity<AspNetUserLogin>().HasKey(e => e.UserId);
        }

        public DbSet<AspNetUser> AspNetUsers { get; set; }        
    }
}

我的控制员......

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using tvc.DAL;
using userModel;

namespace tvc.Controllers
{
    public class UserController : Controller
    {
        private usersContext db = new usersContext();
        // GET: User
        //[Authorize(Roles = "Admin")]
        public ActionResult Index()
        {
            List<AspNetUser> u = db.AspNetUsers.ToList();
            return View(u);
        }
    }
}

u成功返回,但为null。我可以在ssms中访问数据库并成功查询用户表。

0 个答案:

没有答案