【发布时间】: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