- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我能够升级我的 .NetStandard2.0 项目以使用 EntityFrameworkCore 3.1.4 并创建一个 nuget 包。
现在我想在我的 netcoreapp2.2 项目中使用那个 nuget 包。
但是,当我尝试通过 nuget 添加包时,我得到了
Error NU1107 Version conflict detected for Microsoft.EntityFrameworkCore. Install/reference Microsoft.EntityFrameworkCore 3.1.4 directly to project MyApi to resolve this issue.
MyApi -> SBDSTD.Standard 1.0.0-CI-20200526-230146 -> Microsoft.EntityFrameworkCore (>= 3.1.4)
MyApi -> Microsoft.AspNetCore.App 2.2.0 -> Microsoft.EntityFrameworkCore (>= 2.2.0 && < 2.3.0). MyApi D:\dev\MyApi\MyApi\MyApi.csproj 1
所以我尝试使用安装 Entity Framework 包
Install-Package Microsoft.EntityFrameworkCore -Version 3.1.4
我得到了
NU1608: Detected package version outside of dependency constraint: Microsoft.AspNetCore.App 2.2.0 requires Microsoft.EntityFrameworkCore (>= 2.2.0 && < 2.3.0) but version Microsoft.EntityFrameworkCore 3.1.4 was resolved.
Install-Package : NU1107: Version conflict detected for Microsoft.EntityFrameworkCore.Abstractions. Install/reference Microsoft.EntityFrameworkCore.Abstractions 3.1.4 directly to project
MyApito resolve this issue.
MyApi-> Microsoft.EntityFrameworkCore 3.1.4 -> Microsoft.EntityFrameworkCore.Abstractions (>= 3.1.4)
MyApi-> Microsoft.AspNetCore.App 2.2.0 -> Microsoft.EntityFrameworkCore.Abstractions (>= 2.2.0 && < 2.3.0).
At line:1 char:1
+ Install-Package Microsoft.EntityFrameworkCore -Version 3.1.4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Install-Package], Exception
+ FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
我不愿意开始尝试安装建议的包,因为我刚刚花了半天时间在包管理器 UI 中做类似的事情[更新]当我开始通过 Nuget 安装时,我看到一条消息
Detected package version outside of dependency constraint:Microsoft.EntityFrameworkCore.Abstractions (>=2.2.0 && < 2.3.0) butversion Microsoft.EntityFrameworkCore.Abstractions 3.1.5 was resolved
如果我将我的库回滚到使用 EntityFrameworkCore 2.2.0 并且必须将所有 Microsoft.Data.SqlClient 更改为 System.Data.SqlClient 引用。
[更新]按照 Lauxjpn 的建议并粘贴我得到的引用资料
我开始尝试解决错误。我得到的第一个错误是在
using Remotion.Linq.Clauses;
我只是简单地注释掉了。
然后我就到了
CS0619 'RelationalQueryableExtensions.FromSql<TEntity>(IQueryable<TEntity>, RawSqlString, params object[])' is obsolete: 'For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query
最佳答案
根本问题是,Microsoft.AspNetCore.App
元包引用了 EF Core(和其他)包的特定版本范围。
[...] Install/reference Microsoft.EntityFrameworkCore 3.1.4 directly to project MyApi to resolve this issue.
一个简单的解决方案是执行消息告诉您的操作:将要覆盖的包版本显式添加到目标项目。
假设一个简单的原始项目文件如下:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
</Project>
然后以下将使您的项目编译:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<!-- Manually override all conflicting packages we care about and their
dependencies, that are referenced by `Microsoft.AspNetCore.App`. -->
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Primitives" Version="3.1.4" />
</ItemGroup>
</Project>
但是,这会导致一些警告。如果您不想要这些,则必须引用各个包,Microsoft.AspNetCore.App
元包可以方便地为您组合,并适当更新它们的版本:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>
<ItemGroup>
<!-- Don't use the meta package anymore. We will explicitly reference
all actual packages instead.-->
<!--<PackageReference Include="Microsoft.AspNetCore.App" />-->
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
<!-- Manually include all packages from "Microsoft.AspNetCore.App",
and update all package versions unrelated to ASP.NET Core. -->
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.6"/>
<PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Core" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Facebook" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Google" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.MicrosoftAccount" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.Twitter" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.WsFederation" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Connections.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.Internal" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Cryptography.KeyDerivation" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.DataProtection.Extensions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.DataProtection" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.HostFiltering" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Http.Connections.Common" Version="1.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.Http.Connections" Version="1.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.HttpOverrides" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Localization.Routing" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Localization" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.MiddlewareAnalysis" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Analyzers" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Xml" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Localization" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.Extensions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.NodeServices" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Language" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.ResponseCaching" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Routing.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.HttpSys" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.IIS" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Core" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Https" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Session" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Common" Version="1.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.Json" Version="1.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0"/>
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.WebSockets" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.Razor" Version="2.2.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Analyzers" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.4"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Ini" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.KeyPerFile" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.FileProviders.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.FileProviders.Composite" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.FileProviders.Physical" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Http" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="2.2.0"/>
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="2.2.0"/>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Localization" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging.EventSource" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging.TraceSource" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.ObjectPool" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Options" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.Primitives" Version="3.1.4"/>
<PackageReference Include="Microsoft.Extensions.WebEncoders" Version="3.1.4"/>
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.0"/>
<PackageReference Include="System.IO.Pipelines" Version="4.5.2"/>
</ItemGroup>
</Project>
对于引用问题解决后现在出现的问题,这些现在是与您从 EF Core 2.2 升级相关的问题。到 3.1.4。
(从技术上讲,这现在是一个完全不同的问题,答案完全不同,并且与您原来的问题无关。因此,我建议下次就 SO 提出一个全新的问题。)
有很多重要的breaking changes在 EF Core 3.0 中,因为查询管道被完全重写。
其中一个变化是,EF Core 不再依赖于 Remotion
。
至于您的 ExecuteSqlQuery()
扩展方法,以下实现应该有效:
public static class DatabaseFacadeExtensions
{
public static RelationalDataReader ExecuteSqlQuery(
this DatabaseFacade databaseFacade,
string sql,
params object[] parameters)
{
var concurrencyDetector = databaseFacade.GetService<IConcurrencyDetector>();
using (concurrencyDetector.EnterCriticalSection())
{
var rawSqlCommand = databaseFacade
.GetService<IRawSqlCommandBuilder>()
.Build(sql, parameters);
var connection = databaseFacade.GetService<IRelationalConnection>();
var parameterObj = new RelationalCommandParameterObject(
connection,
rawSqlCommand.ParameterValues,
null,
null,
null);
return rawSqlCommand.RelationalCommand.ExecuteReader(parameterObj);
}
}
}
CS0619 'RelationalQueryableExtensions.FromSql(IQueryable, RawSqlString, params object[])' is obsolete: 'For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead. Call either new method directly on the DbSet at the root of the query
对于上面的警告,它已经告诉您该怎么做(请改用 FromSqlRaw
或 FromSqlInterpolated
)。这也是 EF Core 3.0 的变化。参见 Raw SQL Queries了解更多信息。
这是一个完全可用的控制台示例,它演示了两种功能(您的 ExecuteSqlQuery()
扩展方法和 FromSqlInterpolated()
):
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.Logging;
namespace IssueConsoleTemplate
{
public class IceCream
{
public int IceCreamId { get; set; }
public string Name { get; set; }
}
public static class DatabaseFacadeExtensions
{
public static RelationalDataReader ExecuteSqlQuery(
this DatabaseFacade databaseFacade,
string sql,
params object[] parameters)
{
var concurrencyDetector = databaseFacade.GetService<IConcurrencyDetector>();
using (concurrencyDetector.EnterCriticalSection())
{
var rawSqlCommand = databaseFacade
.GetService<IRawSqlCommandBuilder>()
.Build(sql, parameters);
var connection = databaseFacade.GetService<IRelationalConnection>();
var parameterObj = new RelationalCommandParameterObject(
connection,
rawSqlCommand.ParameterValues,
null,
null,
null);
return rawSqlCommand.RelationalCommand.ExecuteReader(parameterObj);
}
}
}
public class Context : DbContext
{
public DbSet<IceCream> IceCreams { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder
.UseSqlServer(@"Data Source=.\MSSQL14;Integrated Security=SSPI;Initial Catalog=So63009531")
.UseLoggerFactory(
LoggerFactory.Create(
b => b
.AddConsole()
.AddFilter(level => level >= LogLevel.Information)))
.EnableSensitiveDataLogging()
.EnableDetailedErrors();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<IceCream>()
.HasData(
new IceCream {IceCreamId = 1, Name = "Vanilla"},
new IceCream {IceCreamId = 2, Name = "Chocolate"});
}
}
internal static class Program
{
private static void Main()
{
using var context = new Context();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var iceCreams = context.IceCreams
.OrderBy(u => u.IceCreamId)
.ToList();
var vanillaName = "Vanilla";
var vanillaIceCreamCountReader = context.Database.ExecuteSqlQuery(
@"select count(*) as [IceCreamCount]
from [dbo].[IceCreams]
where Name = @p0;",
vanillaName);
vanillaIceCreamCountReader.Read();
var vanillaIceCreamCount = (int)vanillaIceCreamCountReader.DbDataReader["IceCreamCount"];
vanillaIceCreamCountReader.Dispose();
var chocolateName = "Chocolate";
var chocolateIceCreams = context.IceCreams
.FromSqlInterpolated($"select * from [dbo].[IceCreams] where [Name] = {chocolateName}")
.ToList();
Debug.Assert(iceCreams.Count == 2);
Debug.Assert(vanillaIceCreamCount == 1);
Debug.Assert(chocolateIceCreams.Count == 1);
}
}
}
请注意,由于 EF Core 3.0 中的查询管道发生了重大更改,您的查询可能会与以前不同(关键字为 cartesian explosion)。
关于entity-framework-core - NU1107 : Version conflict detected for Microsoft. EntityFrameworkCore.Abstractions。安装 EFCore 以与 AspNetCore 2.2 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62034467/
我在 sklearn 中使用 NuSVC 类。在尝试如下实例化 NuSVC 对象之后: self.classifier = OneVsRestClassifier(NuSVC()) 我发现我反复收到“
如何设置 Xom.nu,使元素像这样关闭: 而不是 。 我想这样做的原因是,这个 XML 将被导入到一个工具中,不幸的是,该工具识别以前的“关闭标记约定”。 最佳答案 XOM 是一个非常简单的 API
我在将数据从字符串转换为整数时遇到问题。 比如原始数据是这样的 orderdt[1:10,2] [1] 71004 13943 11337 9647 9363 6836 5957 5167
我的一个同事今天注意到 sort 命令有一些奇怪的行为,我想知道是否有人知道这个命令的输出是否是有意的? 给定文件: ABC_22 ABC_43 ABC_1 ABC_1 ABC_43 ABC_10 A
我想在一个文本文件中包含 nu.nl 的新闻标题,这样我就可以在我的一个 bash 脚本中使用它们。我也想用 bash 脚本提取这些标题。 我添加了今天 nu.nl 主页的屏幕截图 (http://i
我正在尝试弄清楚处理这种情况的最佳方法是什么。 假设我有一个被多个不同的不相关解决方案引用的库,我们称它为 WebServiceInterface.dll。该库依赖于 JSON.NET。 在 NuGe
我在玩这个site ,我陷入了 random4 问题。 所以,基本上,问题如下。 var random4 = new function() { var rand = Math.random();
我试图通过以下方式在Grails中将JSON转换为XML: import net.sf.json.JSONObject import net.sf.json.xml.XMLSerializer ...
我想使用 validator.w3.org/nu 的 API。 文档:https://github.com/validator/validator/wiki/Service:-Input:-GET 我
我正在尝试安装本地版本的 Validator.nu 服务器,但它在尝试构建 HTML 解析器时总是失败。 它说它找不到我在 .bashrc 文件中设置的 JAVA_HOME 变量,当我在提示符下键入“
我正在验证 HTML5 页面并返回以下 2 个警告:信息:内容类型为文本/html。使用 HTML 解析器。信息:使用支持 SVG 1.1、MathML 3.0、RDFa 1.1 和 ITS 2.0
关于 paper 的 mercury 说明如下: The if-then-else and negation constructs in most variants of Prolog are non
我正在尝试在 Sklearn 中创建一个 Matern 内核,并将参数 nu 设置为无穷大。 from sklearn.gaussian_process.kernels import Matern i
我正在尝试对具有 5000 列和 30 行的数据框进行 PCA Sample sum(is.na(Sample)) [1] 0 > sum(is.na(Sample.scaled)) [1] 90
在 Ed Kmett 的 recursion-scheme 包中,有三个声明: newtype Fix f = Fix (f (Fix f)) newtype Mu f = Mu (forall a.
我正在使用https://github.com/patternconsulting/opencv将 opencv 3.2.0 包含在我的 maven java 项目中。 我面临的问题是,当我使用
validator.nu gem 抛出 YAJL 弃用警告,偶尔会完全失败,引用 HTTPStream 的问题。是否有任何稳定的 ruby gem 可以验证 HTML5 文档? 例如 req1.9
我对R非常陌生,目前正在尝试创建Siber椭圆。 我观看了使用省略号比较社区成员的potcast :( http://www.tcd.ie/Zoology/research/research/theo
是否可以将 nu.XOM.Element 转换为 org.w3c.dom.Element? 我正在尝试使用 XOM API 构建 XML。但我的旧版 API 很少需要 org.w3c.dom.Elem
我使用了来自 XMLBeans 的 scomp 工具生成 java 类,然后填充 XmlObject 中的字段(我前段时间写了这段代码)。我现在需要将此对象转换为 Element XOM librar
我是一名优秀的程序员,十分优秀!