OData Queries broke when upgrading to .net core 6 - c#

We have encountered an issue during the upgrade from .net framework to .net core related to OData queries. It seems to come from the combination of the following components:
ASP.NET Core 6.0.0
Microsoft.AspNetCore.OData 8.0.11
EntityFramework 6.4.4
The issue is related to $filter and $select clauses when the API methods is returning an IQueryable<T>.
The exception message is "Unable to create a constant value of type 'Microsoft.OData.Edm.IEdmModel'. Only primitive types or enumeration types are supported in this context.".
Has anyone experienced this issue and have a workaround for EF6? Otherwise I guess we have to go straight to EF Core.

Related

EF Core Power Tools - Missing EF Core 5 Version

I am using .NET core 5 and entity framework core 5 version in my project and to generate dB Context I am using EF Core Power Tools but the problem is this tool is not showing me EF Core 5 version in the selection. please refer to the below screenshot
EF Core 5 is no longer supported. If you really need support and are not able to update to EF Core 6 please contact me via the Github repository and I can provide an unsupported version of the tool that works with EF core 5.

Scaffold existing local MS Access via .NET Framework: System.TypeLoadException: Method 'Create' in EntityFrameworkCore.Jet not implemented

I want to represent the datas of an existing local Access DB on a Homepage. For that I use ASP.NET MVC with Framework 4.7.2. I have to use EntityFrameworkCore.Jet, so I can't use Core. Following packages were installed:
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Tools
EntityFrameworkCore.Jet
So I try to scaffold my Database in the Package-Manager-Console:
Scaffold-DbContext “Data Source=C:\...\AKneu.mdb” EntityFrameworkCore.Jet -OutputDir Models
But it throws back an Error:
System.TypeLoadException: The method "Create" in the type "EntityFrameworkCore.Jet.Scaffolding.Internal.JetDatabaseModelFactory" of the assembly "EntityFrameworkCore.Jet, Version = 2.2.0.0, Culture = neutral, PublicKeyToken = adb9793829ddae60" has no implementation.
I couldn't find a reason why it can't find the assembly. Do you have anything in mind, why it doesn't work?
To use scaffolding you need to use Visual Studio 2015, this is mentioned in the wiki of the GitHub project:
If you already have a database, your can use the Package Manager Console Scaffold-DbContext command to create your model classes from an existing database. This feature is only available in Visual Studio 2015.
I had a similar issue a while ago and noted that in order for scaffolding to work you also need to use the version 2.1.2 of EntityFrameworkCore and the 2.0.0 version of the Jet-Provider. Unfortunately I did not note why this was needed, but it may help you.
The issue is that you are trying to use the EFCore.Jet 2.2.0 provider with EF Core 3.x. EF Core 2.2 providers are not compatible with EF Core 3.x and will throw this error due to changes in what EF Core 3.x expects of its providers.
To solve this, use the latest release of EF Core 3.1.x (currently release 3.1.10) with the latest release of EFCore.Jet 3.1.x (currently the prerelease 3.1.0-alpha.4) from nuget.org.
EF Core 3.1 and its providers are .NET Standard 2.0 compliant, and therefore support not just .NET (Core) 2.0+, but also .NET Framework 4.6.1+.

SQL Server Geography datatype with .Net Core 2.1

I understand that the SQL Server geography and geometry datatypes are not currently supported in .Net EF Core, but I'd still like to use them in standard .Net Core 2.1. The Microsoft.SqlServer.Types package does not seem to work in Core, at least not as a default install via NuGet.
Is there support for geography in Core directly or as a work-around? So far, the found references are pre- Core 2.

EF Core compatibility [duplicate]

This question already has answers here:
Entity Framework Core 2.0 on .NET 4.6.1
(4 answers)
Closed 4 years ago.
We are working on bringing an old web forms application into the MVC world. The old application was using an ORM called EntitySpaces, which we will now be switching to EntityFramework as well. Recently we ran into an issue because we are doing code first migrations in EF6 currently but it has no support to set default values via the fluent api, instead you must generate the migration and eidt it to have the default values. This feels dirty to us so we looked into EF core and found that it has a HasDefaultValue() method in the fluent API just like we want.
We are using .net 4.6 for this project because we still need webforms in the project until all the pages are migrated to razor views, then we can look at upgrading to .net Core. In the meantime can we use EF Core with .net 4.6 or does it require .net Core?
Yes, it is. The Microsoft.EntityFrameworkCore package (https://www.nuget.org/packages/microsoft.entityframeworkcore) targets .NET Standard 2.0, which means it can be used by any runtime that supports it, such as .NET 4.6.1. See also https://learn.microsoft.com/en-us/dotnet/standard/net-standard.

Use 'Average()' On EF CORE (C# .NET CORE)

I use .NET CORE for a while now
and i noticed that some queries run really strange, so i did some profiling and i noticed that some queries and running in parts on the database, instead of getting it in 1 shot.
So i turned off the option 'QueryClientEvaluation' from EF core and i keep getting error
The LINQ expression 'Average()' could not be translated and will be evaluated locally.
which is very strange because i used the Average function in EF6 till now with no issue, so why should it need to use QueryClientEvaluation??
here is a simple sample _context.Reviews.Select(r => r.Rating).Average()
Which version are you using?
It was a bug #7190 that has been fixed at version 2.0.0-preview1. You can also have latest released version 2.0.0 .

Categories

Resources