【问题标题】:OrderBy throws Could not load file or assembly System.Data.EntityOrderBy 抛出无法加载文件或程序集 System.Data.Entity
【发布时间】:2018-03-12 23:58:04
【问题描述】:

试图让 DataTables 在 ASP.NET Core 2 项目中工作。当执行以下代码行时,应用程序在 OrderBy

上抛出异常
var data = (from app in _context.Applications select app);

//Sorting  
if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
{ 
    data = data.OrderBy(sortColumn + " " + sortColumnDir);
}

例外是:

{System.TypeInitializationException: The type initializer for 'System.Linq.Dynamic.ExpressionParser' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
   at System.Linq.Dynamic.ExpressionParser..cctor()
   --- End of inner exception stack trace ---
   at System.Linq.Dynamic.ExpressionParser..ctor(ParameterExpression[] parameters, String expression, Object[] values)
   at System.Linq.Dynamic.DynamicQueryable.OrderBy(IQueryable source, String ordering, Object[] values)
   at System.Linq.Dynamic.DynamicQueryable.OrderBy[T](IQueryable`1 source, String ordering, Object[] values)
   at assetreportv2.Controllers.HomeController.LoadData() in C:\Users\chentiangemalc\Documents\Visual Studio 2017\Projects\DataTableTest\DataTableTest\Controllers\HomeController.cs:line 64}

csproj 文件当前配置如下:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="bootstrap" Version="4.0.0" />
    <PackageReference Include="Entityframework" Version="6.2.0" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Http" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.2" />
    <PackageReference Include="System.Linq.Dynamic" Version="1.0.7" />
    <PackageReference Include="WindowsAzure.Storage" Version="8.3.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.1" />
  </ItemGroup>

  <ItemGroup>
    <WCFMetadata Include="Connected Services" />
  </ItemGroup>

</Project>

有没有办法在 ASP.NET Core 中使用这个 OrderBy,或者建议一个替代选项?

【问题讨论】:

    标签: c# asp.net-core entity-framework-core


    【解决方案1】:

    抱歉,我回答你的问题有点晚了,但我确实遇到了这个问题,我刚刚解决了这个问题。我也在使用 Core 2.0 并且正在使用 System.Linq.Dynamic 并在使用 OrderBy 扩展时出现该错误,但我将其卸载并安装了 System.Linq.Dynamic.Core,现在它运行良好

    【讨论】:

    • 感谢您的回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2016-12-16
    • 2020-11-30
    • 2012-10-15
    • 2020-08-17
    相关资源
    最近更新 更多