【问题标题】:Visual Studio 2015 Database projectVisual Studio 2015 数据库项目
【发布时间】:2017-08-14 15:41:35
【问题描述】:

我需要在数据库项目中排除一些表的发布,主要思想是根据构建配置仅发布表的子集,如果是 Debug 我想发布所有表但如果配置是 Release I只想发布这些表的一个子集。

【问题讨论】:

标签: sql database visual-studio-2015 database-deployment


【解决方案1】:

试试这个代码:

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多