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 .
Related
We are trying to upgrade our .Net core 2.1 app to use .Net 6. I used tried to use the upgrade assistant here, https://dotnet.microsoft.com/en-us/platform/upgrade-assistant/tutorial/install-upgrade-assistant
We now get many errors but the one that is confusing me is the naming, Is .NetFramework,Version 6.0 the same a .Net 6? I thought framework was old stuff?
Also as you can see from the error example below, it seems that our current nuget packages are not compatible with the new code, if I have read that right. Should we have set the nuget packages to be .Net Standard 2.1 to get around this?
Ok so I should not have tried to use the upgrade assistant, that seems to be for framework relates code. Instead following steps here https://learn.microsoft.com/en-us/aspnet/core/migration/21-to-22?view=aspnetcore-5.0&tabs=visual-studio for each version. Not ideal as would like an easier solution, but at least it gives some guidelines.
So basically im trying to do my first application/backend system on EF 6.0 the thing is that due to nomenclature's i started confusing .NET and .NET framework and by the looks of it im not alone causing what seems like a bunch of issues.
Im doing code first and i want my models to be automatically turned into sql tables on a azure sql database, but after trying to run add-migration he complains about needing a config file first so i decided to install ef globally through the cli instead of nugget console manager and then ran dotnet ef migrations script -i but it complains about circular dependacies involving "GetEFProjectMetadata". and after bigging through google all of the migrations seem to use .net core 6.0
So do i need to once again migrate my whole project to .net core 6.0? or is there a way to use .net framework 6.0?
If the question came rushed or i didn't detail enough info, im sorry, as i tipically work in linux and my system is in my native language so translating would either be somewhat time consuming or wouldn't be the 1:1 error message
Edit:
here's the error i was refering to:
(*drive path up to user*)\OneDrive\Documents\Visual Studio 2022\Projects\MakrBackend(solution root, it was refactored to Makr-Backend once though strangely it didn't change the actual folder name)\Makr-Backend(project)\obj\Makr-Backend.csproj.EntityFrameworkCore.targets(4,5): error MSB4006: Há uma dependência circular no elemento gráfico de dependência circular de destino envolvendo o destino "GetEFProjectMetadata". [(*drive path up to user*)\OneDrive\Documents\Visual Studio 2022\Projects\MakrBackend\Makr-Backend\Makr-Backend.csproj]
Unable to retrieve project metadata. Ensure it's an SDK-style project. If you're using a custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.
To reproduce it in my machine i just go to show->terminal which apparently opens an embuted power shell in which i write dotnet-ef migrations add InitDB
dotnet was installed globally and writting dotnet-ef replies me with some simple ascii hart of an unicorn along with some generic help suggestions and arguments info
As suggested earlier the solution was wiped several times due to me not being able to use Entity framework, the latest try i decided to not put the hypen (Makr-Backend) due to fears of data persistance as such later in the project i renamed the solution to Makr-Backend and created a new project with the same name, although i deleted the project without a hyphen im aware that he still is present in the root directory although i tipically make shure im not adressing that folder, the only reason i haven't whiped it out of the system is that it contains the graphs i was intending to use as a model for the database
Another Edit apparently entity framework and entity framework core are radically different things and I've finally managed to do what i wanted by migrating the project to .net core and using exclusively a entity framework core aproach and i finally managed to populate my azure database
"dotnet ef" is the cli tool for Entity Framework Core. Don't confuse it with Entity Framework.
You don't necessarily need to upgrade your app to .NET 6
You can check the Entity Framework Core documentation on the supported versions.
Also I believe this article will help you better understand the naming.
Basically, i am trying to determin if an application made for 1.x will run on a computer with just one copy of the .NET framework installed which is a higher version than what i am targetting, ie: it only has one copy of .NET 2.0, or 3.0, or 3.5 or 4.0 - has one copy of either of these and thats it, the hypothetical computer would not have 1.0 or 1.1 installed.
Trying to determine if 1.0 or 1.1 app would run here - the app is a simple app and im just trying to get the largest reach possible without the need to install the framework (and yes, i realize the frameworks are really small now days at about 40mb, but this is still not an option for me). thanks
an aside: btw, i have googled this to no avail, do we have or does anyone know adoption stats in terms of % of windows computers that run (say) 2.0, 1.x, 3.5 etc... or 2.0 and above, or 1.x and above? there is a reference on scott hanselmans blog but this seems really optimistic and incorrect to me as i did some user-string analysis of common users, and adoption of 2.0+ was barely above 50% while hanselmen said according to windows update data it was 95% (and this was in janruary 2010).
Edit\Update Could someone please confirm if Nayan's answer (and Daniels point under Darins answer) is correct? If so, this would change everything!
Yes it will run fine if you have a higher version of the framework installed. It is backwards compatible. But in the end of 2010 there's very little sense in still keeping applications targeting .NET 1.*. You could at least recompile them to target the .NET 2.0 if not .NET 3.5 or 4.0.
To answer your aside the wikipedia page shows what versions of windows have what version of .net pre-installed by default
To answer your main question. I know 100% that if you have 3.5 it will run 1.0-3.5 with just that installed. However I do not know if that is true for 4.
You should not have any problems running your application on .net 1+ frmaeworks.
. Net has been designed to always be backwards compatible. This means if we get to later versions it will still work.
It also means if the Microsoft team make a mistake it will still be there just a better way will be available
I don't think the question is very clear. I'll explain:
If you are asking if the application is already built on .NET 1.x and you are trying to run it in any other version, it will not work. It would need the same version.
But if you still have the code and are willing to recompile it on newer .NET versions, then you will have a newer .NET version compatible app!
What, I feel, missing in your question is that whether you are talking about built up apps or source codes.
I can't find a template for a linq to sql class in .net 2.0 project, based on what i know you can work with linq in .NET 2.0 as long as you have 3.5 in your development machine and ship system.core.dll with your application?
so based on that how can I add a Linq to Sql model to my project when "Linq to Sql Classes" template is missing from the add new item window?
Edit:
Just to clear things up, This is a server application and the server will have .net 3.5 SP1. the only issues is that we can not upgrade the project to .net 3.5 at the moment.
If you ship System.Core with your application, it won't pick up future security fixes and won't have the optimized build installed (MS internally uses and profiling NGEN for distributed framework libraries). Either require .NET 3.5, avoid using Linq, or implement your own extensions for a custom Linq provider.
The approach you are taking is dangerous and will almost certainly lead to errors on your deployment machine.
The 3.5 framework, and specifically System.Core.dll, rely on the CLR being at least 2.0 SP1. There are several bugs in CLR 2.0 that are exposed by the use of the expression tree API and other code which Linq2Sql relies upon.
If you ship System.Core.dll only the clients are not guaranteed to have, and likely won't have, the CLR service pack. Hitting any of these bugs will result in hard to understand failures in your application.
You may get lucky for awhile but this is an untested and unsupported scenario.
I highly advise you to not do this
Try adding a reference to System.Core
http://iformattable.blogspot.com/2008/05/using-linq-from-net-20.html
I figured it out, All you have to do is add a new text file to the project, but change the extension from .txt to .dbml and it'll automatically be picked up by visual studio. it will even generate all the code behind for you.
I can't seem to get my application up and running on my dev server and I'm not sure why.
I have compiled my code in VS 2008 with a target framework of 3.5. I am using 3.5 mainly because I have implemented LINQ rather extensively. Compiling and runs local without any problems.
The hang up is that my server only has the 2.0 .Net framework and upgrading to 3.5 is apparently not going to happen.
I was under the impression after doing some research that as long as I was trying to execute compiled code the server would not need 3.5 installed.
Today I am trying to publish to the server and I can't get past this error in my WEB.CONFIG
Configuration Error
Parser Error Message: Child nodes not allowed.
providerOption name="CompilerVersion" value="v3.5"/
EDIT ADD ON QUESTION:
I have seen some posts about possibly setting my references to "copy local" which might allow me to run on the 2.0 server. Thoughts?
You are right in that 3.5 runs on the 2.0 CLR, but 3.5 contains libraries and if you have used any of those, you're out of luck unless you install 3.5 on that server.
There are plenty of options for a 3.5 program to not run correctly on only 2.0, so I'd consider downgrading the program, or upgrading the server.
Note regarding copy local. Even if you copy all the 3.5 libraries that your app uses, there is no guarantee it'll work and most likely it won't. Even so, distributing the libraries with your app is expressively prohibited by the .NET license.
Since you have stated you use LINQ, the only legal way to get your app running is to install the 3.5 license.
Or, you can rewrite your app using only 2.0.
I'm pretty sure that LINQ is one of the things that makes 3.5 a requirement. A lot of the other things, like lambda expressions etc. are just compiler trickery.
Because System.Linq is a 3.5 feature, the framework is required to be that version.
A good way to determine would be to change the target framework to 2.0 and see if it builds.
Code compiled against 3.0 or 3.5 may run on the 2.0 framework, but only if you do not use any libraries that are specific to the 3.0+ framework. One good way to find what's causing your code to fail is to switch your target to 2.0 and change things so that it compiles. Since one of your target installations is .NET 2.0, you are going to have to write .NET 2.0 code; this is not unique to .NET. In the past, writing an application that executed in both Win95 and WinNT involved extra work for the developer to carefully make sure the appropriate API was used.
Technically, 3.5-targetted code can run on 2.0 with no problems, but there's some gotchas you have to watch for. If anything accesses something that is unavailable in .NET 2.0, that will fail. This doesn't happen when the application starts, it happens when the application tries to make the call. I tested this by making a console application that does a little bit of output, then tries to display a WPF window. The output is made, but the application throws an exception when it tries to display the window on a machine with nothing but .NET 2.0.
Another gotcha is that VS 2008 actually comes with the .NET Framework 2.0 SP1, and there are a few types and methods in SP1 that are not in the normal 2.0 Framework. Visual Studio will not flag these methods as unsafe.
Finally, if this is a web application, the default web.config file for 3.5-targeted projects is very different than the web.config file for 2.0-targeted projects. Make sure you're distributing a compatible web.config. This is likely the problem you are encountering. A cheap workaround might be to change your target to .NET 2.0, copy that web.config, and use it in this case. Keep in mind that if you are using any 3.0+-specific language features or types your code will still fail, but this should get you past the web.config.
You're not going to be able to run code targetted to 3.5 on the server unless you get 3.5 installed on it.
The problem isn't your code, rather that the required libraries will be missing.
This is not possible. Although the CLR has not changed (like it did between v1.1 and v2.0) The libraries have. You cannot run a 3.5 app that doesn't have the 3.5 fraework installed. All of the Linq features are made possible by the 3.5 framework.
One error is in Web.Config. The published Web.Config is setup to allow compilation from .NET 3.5, which is the reason it includes build provider information.
Beyond that, your code won't run. By using LINQ, you're referencing assemblies that don't exist in .NET 2.0.
I was just going to leave a comment by my rep is not quite there. I agree with the crowd so far and believe that lassevk's answer is the best so please give him the rep for that. One this I wanted you to know about though is that once you install 3.5 on your IIS server (6 or better). When you go to the IIS Manager and right click on your website to access the ASP.Net tab. You will see AFTER the install of the 3.5 Framework that there is no 3.5 option available. It will still show it as 2.0.50727. Don't worry about that, it will still work just fine. Because of this inconsistence (thanks Microsoft) some confusion has been caused. Actually I think this is why you may have thought that 2.0 would run your 3.5 code just fine. Hope this helps and anyone please edit this so it makes more sense.
You can may use of some C# 3 features whilst targeting .NET 2.0. Its the language features which by the time its compilied to IL will run on the 2.0 CLR regardless of whether that CLR is part of a 2.0 or higher framework install.
Hence you can use anonymous types, extension methods and Lambda expressions but as soon as you do things like LINQ you then need external libraries that are part of 3.5
If you are only doing LINQ to Object you could add the LINQBridge to your distribution.
Another problem you can run into is if you are shipping a web application that includes the source code, such as code behind files, in line code and .cs in the App_Code folder.
You can end up shipping C# source code which compiles on the developement machine with C# 3 compilier present but fails to compile on a server only equiped with C# 2. In this case you can't use any new language features either.
What's worse is that specifing the .NET 2.0 framework as the target in the Visual Studio doesn't stop you using C# 3 language features. You get no warnings that such syntax will not compile on a 2.0 machine.
Hence if you are shipping such a web app, you'll need to compile pretty much everything first.
You can just copy over the 3.5 dlls onto the server. You can absolutely run 3.5 code on a 2.0 server.