Closed CriggerMarg closed 4 years ago
@CriggerMarg As it says at the end of the page, the 2.2 methods were renamed. See also https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes#fromsql
@ajcvickers Thing is there is no such methods at all in Microsoft.EntityFrameworkCore v 3.1.4.
Look at https://github.com/dotnet/efcore/blob/master/src/EFCore/DbSet.cs code
@CriggerMarg It does. From the page:
EF Core version 2.2 and earlier had two overloads of method named FromSql, which behaved in the same way as the newer FromSqlRaw and FromSqlInterpolated. It was easy to accidentally call the raw string method when the intent was to call the interpolated string method, and the other way around. Calling wrong overload accidentally could result in queries not being parameterized when they should have been.
@ajcvickers there is no any method in DbSet class that starting with "From...".
public static RelationalDataReader ExecuteSqlQuery(this DatabaseFacade databaseFacade, string sql, params object[] parameters)
{
var concurrencyDetector = databaseFacade.GetService
using (concurrencyDetector.EnterCriticalSection())
{
var rawSqlCommand = databaseFacade
.GetService<IRawSqlCommandBuilder>()
.Build(sql, parameters);
return rawSqlCommand
.RelationalCommand
.ExecuteReader(
databaseFacade.GetService<IRelationalConnection>(),
parameterValues: rawSqlCommand.ParameterValues);
}
}
This method is no longer working (after update to Core 3.1.4) -- any ideas on where to start with getting it working?
@ajcvickers thing is I installed ef core 3.1.4 and I don't have these methods at all.
Do you have the required using statement?
Ok I fugured that out.
To get RelationalQueryableExtensions methods family working in my app I had to install Microsoft.EntityFrameworkCore.Relational package.
It's not listed anywhere in documentation. Please update it, or let me create PR. Let me know which option would work for you.
@CriggerMarg What packages did you have installed?
@ErikEJ here is my sample project csproj file, whole.
Project Sdk="Microsoft.NET.Sdk">
PropertyGroup> OutputType>Exe TargetFramework>netcoreapp3.1 /PropertyGroup>
ItemGroup> PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.4" /> PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.4" /> /ItemGroup>
/Project>
You need to mark all the xml as code in markup
I tried, but gave up. So removed all opened tags
So originally you only had Microsoft.EntityFrameworkCore installed?? That is very unusual.
How should I know to install other packages? They didn't installed automatically nor from package manager and from popup when I typed DbContext in my code.
Could you point me where Microsoft.EntityFrameworkCore.Relational is listed in this article please?
Installing a relational provider will due to NuGet magic automatically install Microsoft.EntityFrameworkCore.Relational. https://docs.microsoft.com/en-us/nuget/concepts/package-installation-process
Does not happenning when you install InMemory adapter though.
I think it's not constructive to mention different part of documentation when I clearly pointed what's wrong with this particular one and suggested how to fix it to avoid confusion.
@CriggerMarg InMemory brings in Microsoft.EntityFrameworkCore, but not Microsoft.EntityFrameworkCore.Relational, because InMemory isn't a relational provider. That's why the raw SQL methods aren't available there - InMemory cannot run SQL...
@roji that makes sense, thank you! Could it still be mentioned in documentation?
Still there is a man who got confused so there is room for improvement
Submitted #2402 to specifically call out the lack of raw SQL support in InMemory.
Great, I'll closing this one
Reopening, to be closed when the PR is merged.
It seems that EF Core 3.1 does not contain raw sql methods anymore
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.