Visual Studio 2015 Database project

45 Views Asked by At

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.

1

There are 1 best solutions below

0
Artur Poniedziałek On

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();
    }

}