Asp.net mvc 4 MVC4基座(connectionStringOrName)
我已经搜索了很多页面,但仍然不知道base(connectionStringOrName)的函数。有人能帮忙回答吗?谢谢Asp.net mvc 4 MVC4基座(connectionStringOrName),asp.net-mvc-4,connection-string,Asp.net Mvc 4,Connection String,我已经搜索了很多页面,但仍然不知道base(connectionStringOrName)的函数。有人能帮忙回答吗?谢谢 public class UsersContext : DbContext { public UsersContext() : base("DefaultConnection") { } public DbSet<UserProfile> UserProfiles { get; set; } } public类用
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
public类用户上下文:DbContext
{
公共用户上下文()
:base(“默认连接”)
{
}
公共数据库集用户配置文件{get;set;}
}
base(…)
调用具有这些参数的base DbContext类中的构造函数
- 在本例中,
publicDBContext(字符串名称或连接字符串){…}
public class A {
// note there is no paramaterless constructor
public A(string message) {
Console.WriteLine("In A: " + message);
}
}
public class B : A {
public B() : base("from class B") {
Console.WriteLine("B's Constructor");
}
}
public class C : A {
public C() : base("from class C") {}
}
var b = new B();
var c = new C();
// Output
// In A: from class B
// B's Constructor
/// In A: from class C
谢谢我应该在什么时候在我的模型中使用base(“DefaultConnection”)&DbContext?您在这里尝试做什么?
base(connectionStringOrName)
的目标是什么?