How does the compiler know what datatype the lambda expression should be

c# ef-core-3.0 entity-framework-core lambda

Question

Consequently, you really utilize the majority of the Linq extensions while using EF Core.System.Linq.Expressions rather than the customaryFunc .

Let's assume that you are utilizingFirstOrDefault on aDbSet .

DbContext.Foos.FirstOrDefault(x=> x.Bar == true);

Once youctrl + lmb on FirstOrDefault You will see the overload listed below:

public static TSource FirstOrDefault<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate)

However, there is also a burden forFunc :

public static TSource FirstOrDefault<TSource>(this IEnumerable<TSource> source, Func<TSource, bool> predicate)

You can perform something like the following when you wish to save an expression in a variable:

Func<Entity, bool> = x => x.Bar == true;

and

Expression<Func<Entity, bool>> = x => x.Bar == true;

So, when utilizing these extension methods, how does the compiler choose which overload to use?

1
1
10/2/2019 10:35:53 AM

Accepted Answer

ZZZ_tmp
3
10/3/2019 8:47:37 AM

Popular Answer

ZZZ_tmp






Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow