Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Core 2.2 LINQ query not working in EF Core 3.0

Below code works fine at EF Core 2.2 bu not working on EF core 3.0

 var items = (from asset in Context.Assets               join assetCategory in Context.AssetCategories on asset.CategoryId equals assetCategory.Id               group assetCategory by assetCategory.Id into assetCategories               select new AssetCategorySummary               {                   CategoryId = assetCategories.Key,                   CategoryName = assetCategories.Select(p => p.CategoryName).FirstOrDefault(),                   TotalAsset = assetCategories.Count()               }).ToListAsync(); 

the error I am getting:

Processing of the LINQ expression 'AsQueryable(Select<AssetCategory, string>( source: NavigationTreeExpression Value: default(IGrouping<Guid, AssetCategory>) Expression: (Unhandled parameter: e), selector: (p) => p.CategoryName))' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.

need help please

like image 552
S. Aziz Kazdal Avatar asked Sep 25 '19 07:09

S. Aziz Kazdal


People also ask

Can I use LINQ with Entity Framework?

Entity Framework Core uses Language-Integrated Query (LINQ) to query data from the database. LINQ allows you to use C# (or your . NET language of choice) to write strongly typed queries.

When LINQ query is executed?

LINQ queries are always executed when the query variable is iterated over, not when the query variable is created. This is called deferred execution. You can also force a query to execute immediately, which is useful for caching query results. This is described later in this topic.

Can we use LINQ without Entity Framework?

No. Linq as in query over the data-in-memory that was loaded using your stored procedures (which means that your queries won't be translated to SQL)?


Video Answer


1 Answers

This is due to one of the breaking changes in EF Core 3.0 and that is: LINQ queries are no longer evaluated on the client

So write the query in such way that EF Core can convert the expression into T-SQL or fetch the data into memory and then make your query.

like image 70
TanvirArjel Avatar answered Sep 22 '22 14:09

TanvirArjel