score:7

Accepted answer

this should work in linq to objects if getdistance() returns a boolean - it will not work with linq to entities since it will try to map your method to a sql equivalent, which of course there is none.

as a crude workaround you could use asenumerable() but that would materialize all your types so is not recommended if your table is larger:

mytypes = mytypes.asenumerable()
                 .where(x => getdistance(x.zip, givenzip) < 10);

another way would be to map zip codes to geographic locations in the database and use those locations directly with the soon to be supported spatial data types - this is probably the best approach in my opinion, but not production-ready. of course if you are restricted to just sql server you could just use a store query directly to use geo-locations - but that would work around ef.

score:0

assuming:

list<mytype> mytypes;

try:

mytypes = mytypes.where(x => getdistance(x.zip, givenzip) < 10).tolist();

score:3

this will throw an error because the runtime tries to convert your expression tree into sql. the function 'getdistance' cannot be converted.

have a look at model defined functions. they allow you to define a custom function in your edmx which you can execute when building queries.


Related Query

More Query from same tag