class InvoiceAppDBContext: DbContext
{
public InvoiceAppDBContext() : base("InvoiceDBContext")
{
}
public DbSet<Users> User { get; set; }
public DbSet<Invoice> Invoices { get; set; }
}
class DataBaseUserRespository : IUser
{
private InvoiceAppDBContext _dbContext;
public DataBaseUserRespository()
{
_dbContext = new InvoiceAppDBContext();
}
public IEnumerable<Users> _userList
{
get
{
return _dbContext.User; // this is not working _userlist is showing null when i run it
}
}
public void SaveUser(Users user)
{
if(user.UserId == 0)
{
_dbContext.User.Add(user);
}
else
{
Users userEntity = _dbContext.User.Find(user.UserId);
userEntity.Change(user);
}
_dbContext.SaveChanges();
}
}
所以DBSet
或DBcontext
没有从表中获取数据并将其放入IEnumerable<Users>
列表中。
here i am debugging the userlist(accountList) and it is not showing data
希望这能解释我遇到的问题:)