I need to exclude some tables from publishing in a database project, the main idea is to publish only a subset of tables depending on the build configuration, if it's Debug I want to publish all the tables but if the configuration is Release I want to publish just a subset of those tables.
Asked
Active
Viewed 40 times
-2
-
possible duplicate [Database project](https://stackoverflow.com/questions/35165688/how-to-publish-visual-studio-database-project-in-vs-2015) – Khalil Aug 14 '17 at 16:04
-
Found at: https://stackoverflow.com/questions/25531250/vs-2013-database-project-post-deployment-scripts-to-run-based-off-of-build-conf – Hardys Perez Bermudez Aug 14 '17 at 19:44
1 Answers
0
Try this code:
[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();
}
}

Artur Poniedziałek
- 141
- 7