-2

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

4

1 回答 1

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

}
于 2017-08-14T17:57:13.477 回答