【发布时间】:2013-09-05 10:10:34
【问题描述】:
它自动生成类的方式,它不将连接字符串作为参数 - 尽管生成代码将一个传递给基类。我可以自己编辑模板,但没有更好的方法,因为我可能会重新生成模型(甚至可能删除并重新创建)并且我不希望它影响模板。
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
public partial class MyEntities : DbContext
{
public MyEntities()
: base("<Connection string>")
{
}
...
我使用的是数据库优先方法。一切正常,但现在我已经创建了数据库的精确副本,我需要能够在两者之间切换。
【问题讨论】:
-
我假设您使用的是数据库优先方法?
-
默认情况下,如果使用 DB first 方法,则连接字符串来自您的 config 文件。
标签: c# entity-framework