我是简单会员的新手,我正试图从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中访问数据库并成功查询用户表。