111,098
社区成员




public partial class LocalDbContext : DbContext
{
public LocalDbContext()
: base("name=LocalDbContext")
{
}
}
public partial class LocalDbContext : DbContext
{
public LocalDbContext()
: base("name=LocalDbContext")
{
}
}
[/quote]
还不明白吗?这句话的意思是,EF启动时,使用的配置就是配置文件中的"name=LocalDbContext"的配置,你程序中去改
是没用的。你必须用其他的构造方法代替它
看EF给你提供的几种:
public DbContext(string nameOrConnectionString);
//
// 摘要:
// Constructs a new context instance using the existing connection to connect
// to a database. The connection will not be disposed when the context is disposed
// if contextOwnsConnection is false.
//
// 参数:
// existingConnection:
// An existing connection to use for the new context.
//
// contextOwnsConnection:
// If set to true the connection is disposed when the context is disposed, otherwise
// the caller must dispose the connection.
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext(DbConnection existingConnection, bool contextOwnsConnection);
//
// 摘要:
// Constructs a new context instance around an existing ObjectContext.
//
// 参数:
// objectContext:
// An existing ObjectContext to wrap with the new context.
//
// dbContextOwnsObjectContext:
// If set to true the ObjectContext is disposed when the DbContext is disposed,
// otherwise the caller must dispose the connection.
public DbContext(ObjectContext objectContext, bool dbContextOwnsObjectContext);
//
// 摘要:
// Constructs a new context instance using the given string as the name or connection
// string for the database to which a connection will be made, and initializes
// it from the given model. See the class remarks for how this is used to create
// a connection.
//
// 参数:
// nameOrConnectionString:
// Either the database name or a connection string.
//
// model:
// The model that will back this context.
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext(string nameOrConnectionString, DbCompiledModel model);
//
// 摘要:
// Constructs a new context instance using the existing connection to connect
// to a database, and initializes it from the given model. The connection will
// not be disposed when the context is disposed if contextOwnsConnection is
// false.
//
// 参数:
// existingConnection:
// An existing connection to use for the new context.
//
// model:
// The model that will back this context.
//
// contextOwnsConnection:
// If set to true the connection is disposed when the context is disposed, otherwise
// the caller must dispose the connection.
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
[SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public DbContext(DbConnection existingConnection, DbCompiledModel model, bool contextOwnsConnection);