我很无聊,我不知道为什么我的数据库显示在数据库中的deafult连接中,我正在使用razor技术在C#MVC4 asp.net中编程,
这是我的UserAccountContext
public class UserAccountContext : DbContext
{
public UserAccountContext()
: base("DefaultConnection")
{
}
public DbSet<UserAccount> UserAccounts { get; set; }
// Methods...
public DbSet<UserProfile> UserProfiles { get; set; }
// Methods...
public IQueryable<UserAccount> GetAll()
{
IQueryable<UserAccount> query = this.UserAccounts;
return query;
}
public UserAccount GetSingle(string _UserName)
{
UserAccount Query = this.GetAll().FirstOrDefault(x => x.UserName == _UserName);
return Query;
}
public void Save(UserAccount _UserAccount)
{
if (_UserAccount.ID == 0)
{
this.UserAccounts.Add(_UserAccount);
this.SaveChanges();
}
else
{
this.SaveChanges();
}
}
}
这是我的UserAccount模型
public class UserAccount
{
// Attributes turns into fields in the database
// These attributes persist in the database
[Key]
public int ID { get; set; }
public int UserId { get; set; }
public string UserName { get; set; }
public string WhoVoted { get; set; }
public double NumberOfVotes { get; set; }
// The following attributes will not persist in the DB
public string UserErrorMessage = string.Empty; // Volatile Variable
// Methods...
public UserAccount() { } //Constructor... This is needed to create the DB Table
public UserAccount(int _UserId, string _UserName) // Other Constructor
{
this.ID = 0;
this.UserId = _UserId;
this.UserName = _UserName;
this.NumberOfVotes = 0.0;
this.WhoVoted = string.Empty;
}
}
我拥有一切,我不知道如何处理数据库,寻求任何帮助。提前谢谢!