小编nam*_*nam的帖子

如何使用EF Core在ASP.NET Core中取消应用迁移

当我PM> Remove-Migration -context BloggingContext使用EF Core在VS2015中运行ASP.NET Core项目时,我收到以下错误:

System.InvalidOperationException: The migration '20160703192724_MyFirstMigration' has already been applied to the database. Unapply it and try again. If the migration has been applied to other databases, consider reverting its changes using a new migration.    at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force) 
    at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.RemoveMigration(String contextType, Boolean force) 
    at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsRemoveCommand.<>c__DisplayClass0_0.<Configure>b__0() 
    at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) 
    at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) 
 The migration '20160703192724_MyFirstMigration' has already been applied to the database. Unapply it and try again. If the migration has …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-core visual-studio-2015 .net-core asp.net-core

139
推荐指数
15
解决办法
10万
查看次数

表达式树lambda可能不包含空传播运算符

问题:price = co?.price ?? 0,以下代码中的行给出了上述错误.但如果我?co.?它删除它工作正常.我试图按照此MSDN例如,他们使用的是?上线select new { person.FirstName, PetName = subpet?.Name ?? String.Empty };所以,看来我需要了解什么时候使用???和何时不.

错误:

表达式树lambda可能不包含空传播运算符

public class CustomerOrdersModelView
{
    public string CustomerID { get; set; }
    public int FY { get; set; }
    public float? price { get; set; }
    ....
    ....
}
public async Task<IActionResult> ProductAnnualReport(string rpt)
{
    var qry = from c in _context.Customers
              join ord in _context.Orders
                on …
Run Code Online (Sandbox Code Playgroud)

c# linq null-coalescing-operator

66
推荐指数
4
解决办法
2万
查看次数

ASP.NET MVC Bundle不在临时服务器上呈现脚本文件.它适用于开发服务器

在我们的ASP.NET MVC 4 Web应用程序中,我们的BundleConfig.cs包括以下内容:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
                        "~/Scripts/jquery-ui-{version}.js"));

            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                        "~/Scripts/jquery.unobtrusive*",
                        "~/Scripts/jquery.validate*"));
            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-*"));
Run Code Online (Sandbox Code Playgroud)

当我们查看开发服务器上主页的html时,即使web.config中的调试模式设置为true,我们也可以看到以下脚本标记<compilation debug="true" targetFramework="4.0" />:

<script src="/AFR/Scripts/jquery-ui-1.8.20.min.js"></script>
<script src="/AFR/Scripts/modernizr-2.5.3.js"></script>
<script src="/AFR/Scripts/jquery-1.7.1.js"></script>
<script src="/AFR/Scripts/jquery-ui-1.8.20.js"></script>
<script src="/AFR/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/AFR/Scripts/jquery.validate.js"></script>
<script src="/AFR/Scripts/jquery.validate.unobtrusive.js"></script>
Run Code Online (Sandbox Code Playgroud)

但是当我们在登台服务器上部署应用程序并查看主页的html(查看源代码)时,除了<script src="/AFR/Scripts/jquery-ui-1.8.20.min.js"></script>缺少所有上述脚本标记.我们已经验证了这些标记中提到的所有文件都在脚本文件夹中.文件夹结构与开发机器上的完全相同.在登台服务器上,web.config fie具有<compilation targetFramework="4.0" />默认情况下debug ="false"的含义.

因此,某些JavaScript函数在登台服务器上失败.登台和开发机器都是Windows 2012.

请帮忙.谢谢.

javascript asp.net-mvc-4

50
推荐指数
3
解决办法
12万
查看次数

无法识别术语"添加 - 迁移"

我正在使用这个MSDN教程在VS2015 PM> Add-Migration MyFirstMigration -context BloggingContext中运行昨天成功运行的命令,但今天它给出了以下错误,这也是其他用户在这里指出的.我甚至从解决方案资源管理器中删除了Migrations文件夹,并从SQL Express 2014 on Win 8.1相同的错误中删除了相应的数据库 即使我跑,Add-Migration MyFirstMigration我得到同样的错误:

Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Add-Migration MyFirstMigration -context BloggingContext
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException …
Run Code Online (Sandbox Code Playgroud)

entity-framework-core visual-studio-2015 asp.net-core

45
推荐指数
11
解决办法
6万
查看次数

ASP.NET核心 - 当前上下文中不存在名称"JsonRequestBehavior"

在我的ASP.NET核心(.NET Framework)项目中,我在以下的Controller Action方法中遇到了错误.我可能缺少什么?或者,有什么工作吗?:

    public class ClientController : Controller
    {
      public ActionResult CountryLookup()
      {
        var countries = new List<SearchTypeAheadEntity>
            {
                new SearchTypeAheadEntity {ShortCode = "US", Name = "United States"},
                new SearchTypeAheadEntity {ShortCode = "CA", Name = "Canada}
            };

        return Json(countries, JsonRequestBehavior.AllowGet);
      }
    }
Run Code Online (Sandbox Code Playgroud)

更新:

请注意以下@NateBarbettini的评论:

  1. JsonRequestBehavior 已在ASP.NET Core 1.0中弃用.
  2. 在下面的@Miguel接受的回复中,return typeaction方法does not特别需要是JsonResult类型.ActionResult或IActionResult也可以.

c# asp.net json visual-studio-2015 asp.net-core

38
推荐指数
2
解决办法
3万
查看次数

Visual Studio 2015无法启动

我们在Windows 7上安装了Visual Studio 2015 Professional.它工作正常.但是,在我们今天从菜单工具 - >'扩展和更新'安装更新后,Visual Studio不再启动了.我们也尝试使用"以管理员身份运行".从"开始"菜单中,我们右键单击"Visual Studio 2015",然后"以管理员身份运行",出现询问权限的常用对话框,单击"是",Visual Studio的启动画面出现一秒钟然后消失.在任务管理器上,它也不会出现.

重新启动系统也无济于事.安装了.NET 4.6,同一系统上的Visual Studio 2012工作正常.

更新1 问题在我们安装上次更新后(从VS2015内部)开始,这与我认为的通用应用程序有关.

更新2 在我启动VS2015的确切时间,在安全部分下生成一个Windows事件日志,如下所示:

EventID 6281
Microsoft-Windows-Security-Auditing
Audit Failure
Message: Code Integrity determined that the page hashes of an image file are not valid.
The file could be improperly signed without page hashes or corrupt due to unauthorized modification.
The invalid hashes could indicate a potential disk device error.
File Name: \Device\HarddiskVolume3\Windows\System32\l3codeca.acm
Run Code Online (Sandbox Code Playgroud)

visual-studio windows-7 visual-studio-2015

34
推荐指数
4
解决办法
3万
查看次数

ASP.NET Core EF Add-Migration命令无法正常工作

在我从同一教程创建的VS2015项目中运行该命令后,遵循此MicrosoftPM> Add-Migration MyFirstMigration教程我得到以下错误,我无法解决:

More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
Run Code Online (Sandbox Code Playgroud)

要点注意

  1. 我正在使用上面的教程,除了我正在使用Individual User Account身份验证而不是No Authentication在教程中使用.
  2. 我是最新发布的 ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
  3. 这是一个新创建的项目.没有其他DbContext手动安装

c# entity-framework-core visual-studio-2015 asp.net-core

31
推荐指数
3
解决办法
4万
查看次数

ASP.NET Core部署到IIS错误:不应在已部署的应用程序中启用开发环境

我按照这篇文章将我的ASP.NET MVC Core 1.0应用程序部署到使用IIS 10的Windows 10上的本地IIS.应用程序已成功部署并打开主页.我正在使用个人用户帐户身份验证.在主页上输入登录名/密码并单击" 登录"按钮时,出现以下错误.我正在使用最新版本的ASP.NET Core和VS2015.我使用VS2015发布向导来发布应用程序.一切都在同一台机器上完成:

处理您的请求时发生错误.

发展模式

交换到开发环境将显示有关发生的错误的更详细信息.
不应在已部署的应用程序中启用开发环境,因为它可能导致向最终用户显示异常的敏感信息.对于本地调试,可以通过将ASPNETCORE_ENVIRONMENT环境变量设置为Development并重新启动应用程序来启用开发环境.

iis visual-studio-2015 asp.net-core

29
推荐指数
7
解决办法
5万
查看次数

如何在Rotativa生成的PDF中显示分页符

在我的ASP.NET MVC 4应用程序中,我有一个索引视图,其中嵌入了几个部分视图.我通过NuGet安装了Rotativa的最新版本1.6.1.现在我可以使用Rotativa将索引页打印到PDF.我想在每个局部视图后在PDF中有一个分页符.如何使用Rotativa实现这一目标?

我试图按照这个例子使用CustomSwitches,但似乎没有一个用于分页符.我用这篇文章来生成PDF

pdf asp.net-mvc rotativa

15
推荐指数
2
解决办法
2万
查看次数

我们可以从现有数据库的选定表中Scaffold DbContext吗?

与以前版本的Entity Framework一样,Entity Framework Core中是否可以仅对现有数据库的选定表进行反向工程,以便从中创建模型类.这个官方的ASP.NET站点反向设计整个数据库.过去,如本ASP.NET教程所示,如果您选择使用旧的EF,您只能对所选的表/视图进行反向工程.

asp.net-mvc entity-framework asp.net-mvc-scaffolding visual-studio-2015 asp.net-core

15
推荐指数
4
解决办法
2万
查看次数