2017-08-14 192 views
-2

我需要从数据库项目中排除一些表的发布,主要想法是根据构建配置发布只有一部分表,如果它是调试我想发布所有表,但如果配置是Release我想发布这些表的一个子集。Visual Studio 2015数据库项目

+0

可能重复[数据库项目(https://stackoverflow.com/questions/35165688/how-to-publish-visual-studio-database-project-in-vs -2015) – Khalil

+0

找到:https://stackoverflow.com/questions/25531250/vs-2013-database-project-post-deployment-scripts-to-run-based-off-of-build-conf –

回答

0

试试这个代码:

[Conditional("RELEASE")] 
public static void InsertConditionally(YourDbContext context) 
{ 
    context.Database.Migrate(); 

    if(!context.Products.Any()) 
    { 
     context.Products.AddRange(
      new Product("name 1 release", "param 1"), 
      new Product("name 2 release", "param 1"), 
      new Product("name 3 release", "param 1") 
      ); 
     context.SaveChanges(); 
    } 


} 


[Conditional("DEBUG")] 
public static void InsertConditionally(YourDbContext context) 
{ 
    context.Database.Migrate(); 

    if (!context.Products.Any()) 
    { 
     context.Products.AddRange(
      new Product("name 1 debug", "param 1"), 
      new Product("name 2 debug", "param 1"), 
      new Product("name 3 debug", "param 1") 
      ); 
     context.SaveChanges(); 
    } 

} 
相关问题