2017-08-14 196 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(); 
    } 

}