Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在数据库MVC4 asp.net中显示新表_C#_Asp.net_Asp.net Mvc_Asp.net Mvc 4_Razor - Fatal编程技术网

C# 在数据库MVC4 asp.net中显示新表

C# 在数据库MVC4 asp.net中显示新表,c#,asp.net,asp.net-mvc,asp.net-mvc-4,razor,C#,Asp.net,Asp.net Mvc,Asp.net Mvc 4,Razor,我不知道为什么我的数据库会显示在数据库中的deafult连接中,我使用razor技术在C#MVC4 asp.net中编程 这是我的UserAccountContext public class UserAccountContext : DbContext { public UserAccountContext() : base("DefaultConnection") { } public DbSet<UserAccount> Use

我不知道为什么我的数据库会显示在数据库中的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();
        }
    }
}

我有一切,我不知道如何处理数据库,期待任何帮助。提前谢谢你

您是否在web.config中设置了connectionString打开web.config文件并检查与此类似的内容跟随此链接可能有助于您在数据库中创建表是的,就是这样
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;
    }
}