我想从我的数据库中获取所有用户名,这样当新用户想要注册时,我可以检查用户名是否已经存在于数据库中。我试着用这个LINQ表达式来做到这一点:不能从LINQ表达式的数据库中获取数据
[AllowAnonymous]
public ActionResult Register()
{
var q = from t in _db.User
select t;
return View();
}
但是,当我debugg它Q变为“儿童无法评价”。 我不知道为什么我得到这个错误,所以我只是发布一些我认为可以处理的东西。
这是我如何定义_db注册方法上面:
FantasySport _db = new FantasySport();
这里是fantasysport数据库模型:
public class FantasySport : DbContext
{
public DbSet<UserProfile> User { get; set; }
public DbSet<Team> Team { get; set; }
public DbSet<TeamPlayer> TeamPlayer { get; set; }
public DbSet<Player> Player { get; set; }
public DbSet<Games> Games { get; set; }
public DbSet<League> League { get; set; }
}
这里是用户配置模式:
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Country { get; set; }
public string City { get; set; }
public int Birthdate { get; set; }
public ICollection<Team> teams { get; set; }
}
你可以发布你正在得到的异常的堆栈跟踪(以及确切的异常消息和异常类型)吗? – Slauma
我用你要求的数据给我的问题添加了一张图片:) –
这是打算的行为:https://entityframework.codeplex.com/workitem/1995。它背后的原因与线程调试和防止副作用有关。 –