Link to home
Start Free TrialLog in
Avatar of programmerist 1983
programmerist 1983Flag for Türkiye

asked on

How can I use Fetch expression delegate method instead of skip and take for better performance in Linq query?

I have a big trouble with my skip take expression in my linq query. When I am looking for an advise , I found that a solution. But I couldn't use it.It created an error like below. How can I solve my issue ? I want to use delegate method like "myQuery.Skip(() => skip).Take(() => take); "that in .NET CORE.

Please look at this article: https://visualstudiomagazine.com/articles/2016/12/06/skip-take-entity-framework-lambda.aspx They claim that "myQuery.Skip(() => skip).Take(() => take);" has faster than "myQuery.Skip(skip).Take(take);" but I got error when appliying delegate versin skip-take method.

Package System.Data.Entity.Repository 2.0.0.1 was restored using .netframework instead of the project target framework .netcoreapp v 2.2. this package may not be fully compatible with your project
using System.Data.Entity

int skip = 5;
int take = 10;

myQuery.Skip(() => skip).Take(() => take);

Open in new window


Error Detail :

Error   CS0121  The call is ambiguous between the following methods or properties: 'Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.Include<TEntity, TProperty>(System.Linq.IQueryable<TEntity>,
System.Linq.Expressions.Expression<System.Func<TEntity, TProperty>>)' and 'System.Data.Entity
Avatar of Duy Pham
Duy Pham
Flag of Viet Nam image

I think you are trying to employee EntityFrameworkCore (6) Skip & Take methods which are ambiguous with System.Linq. Try to remove using System.Linq statement.
Avatar of programmerist 1983

ASKER

Thank you your answer but when I remove System.Linq, WHERE clauses throws :

Severity      Code      Description      Project      File      Line      Suppression State
Error      CS1660      Cannot convert lambda expression to type 'string' because it is not a delegate type
Could it possible to post portions of your code here, especially where you got the errors?
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.