c# - Entity Framework Strings vs lambda... Missing .Execute -


i using entity framework , want execute query , know besr way execute query. best practice , why, , 1 more per-formant.

option 1)

        return             this.storage.customer.oftype<preferred>()             .include("order")             .where("it.id = @customerid , it.customertype = @custype", new objectparameter("customerid ", customerid), new objectparameter("custype", (int)custype))             .execute(mergeoption.overwritechanges)             .singleordefault(); 

or

        return         this.storage.customer.oftype<preferred>()         .include(b  => b.order)         .where(cust => cust.id == customerid && cust.customertype== (int)custype)         .singleordefault(); 

the second question why in option 2 .execute not available? appears red.

thanks in advance.

the performance difference should negligible compared actual data access, need measure it determine sure.

include lambda uses reflection property name calls version string parameter, overhead parsing expression. (this implementation detail, however, subject change)

the benefit of using lambda type safety - using wrong property name in lambda break build, using wrong string fail @ run-time.

the reason execute not available because include lambda parameter extension method on iqueryable<t> returns iqueryable<t> in order chain methods where. include string parameter method on objectquery<t> returns objectquery<t>. execute method on objectquery<t>, not iqueryable<t> not available when use iqueryable methods.


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -