【发布时间】:2020-09-10 05:42:59
【问题描述】:
我是 .net core 2.1 的新手
我正在使用代码优先方法使用 .net core 2.1
问题是当我创建一个新对象 dbcontext 类然后给出错误见下一行
dbcontextstudent db=new dbcontextstudent(); //here give an red line
appsettings.json
},
"ConnectionStrings": {
"sqlserverconn": "Server=DEVISSHAHID; Database=studdbs; User id=xxxx;Password=xxxxx;"
},
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
//connection string
services.AddDbContext<DbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("sqlserverconn")));
student.cs
namespace WebApplication1.Models
{
public class student
{
[Key]
public int studid { get; set; }
public string studname { get; set; }
public string studsalary { get; set; }
public int studage { get; set; }
}
}
dbcontextstudent.cs
namespace WebApplication1.Models
{
public class dbcontextstudent : DbContext
{
public dbcontextstudent(DbContextOptions<dbcontextstudent> options) : base(options)
{
}
public DbSet<student> stud { get; set; }
}
}
HomeController.cs
上面的智能没看懂
我按照智能感知编写代码,但仍然报错我知道错误很明显但没有解决
我在哪个地方做错了?
【问题讨论】:
标签: entity-framework asp.net-core model-view-controller