C# 未为实体框架中的存储过程生成脚本
我使用实体框架使用以下代码创建数据库脚本:C# 未为实体框架中的存储过程生成脚本,c#,sql,.net,sql-server,entity-framework,C#,Sql,.net,Sql Server,Entity Framework,我使用实体框架使用以下代码创建数据库脚本: var dbScript = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript(); 我在实体映射类中使用MapToStoredProcedure()方法。这段代码只生成了一个CREATETABLESQL脚本,没有为存储过程生成sql脚本 如何为存储过程生成SQL脚本?ObjectContext.CreateDatabaseScript()是一个旧的代码路径,因为数
var dbScript = ((IObjectContextAdapter)context).ObjectContext.CreateDatabaseScript();
我在实体映射类中使用MapToStoredProcedure()
方法。这段代码只生成了一个CREATETABLESQL脚本,没有为存储过程生成sql脚本
如何为存储过程生成SQL脚本?ObjectContext.CreateDatabaseScript()是一个旧的代码路径,因为数据库创建现在使用迁移管道创建架构。因此,CreateDatabaseScript不知道如何处理存储过程。 使用此代码:
var configuration = new DbMigrationsConfiguration
{
AutomaticMigrationsEnabled = true,
ContextType = typeof(MyContext),
MigrationsAssembly = typeof(MyContext).Assembly
};
var migrator = new DbMigrator(configuration);
var scriptor = new MigratorScriptingDecorator(migrator);
string script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
Console.WriteLine(script);
ObjectContext.CreateDatabaseScript()是一个旧的代码路径,因为数据库创建现在使用迁移管道来创建架构。因此,CreateDatabaseScript不知道如何处理存储过程。 使用此代码:
var configuration = new DbMigrationsConfiguration
{
AutomaticMigrationsEnabled = true,
ContextType = typeof(MyContext),
MigrationsAssembly = typeof(MyContext).Assembly
};
var migrator = new DbMigrator(configuration);
var scriptor = new MigratorScriptingDecorator(migrator);
string script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
Console.WriteLine(script);
ObjectContext.CreateDatabaseScript()是一个旧的代码路径,因为数据库创建现在使用迁移管道来创建架构。因此,CreateDatabaseScript不知道如何处理存储过程。 使用此代码:
var configuration = new DbMigrationsConfiguration
{
AutomaticMigrationsEnabled = true,
ContextType = typeof(MyContext),
MigrationsAssembly = typeof(MyContext).Assembly
};
var migrator = new DbMigrator(configuration);
var scriptor = new MigratorScriptingDecorator(migrator);
string script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
Console.WriteLine(script);
ObjectContext.CreateDatabaseScript()是一个旧的代码路径,因为数据库创建现在使用迁移管道来创建架构。因此,CreateDatabaseScript不知道如何处理存储过程。 使用此代码:
var configuration = new DbMigrationsConfiguration
{
AutomaticMigrationsEnabled = true,
ContextType = typeof(MyContext),
MigrationsAssembly = typeof(MyContext).Assembly
};
var migrator = new DbMigrator(configuration);
var scriptor = new MigratorScriptingDecorator(migrator);
string script = scriptor.ScriptUpdate(sourceMigration: null, targetMigration: null);
Console.WriteLine(script);