这失败并出现错误:
private IQueryable<Field> PrepareAllFieldsQuery( ref DbGeography geo, int page, int amount, string sort, string order, ISearchCriteria searchCriteria )
{
var query = this.context.Fields
.Where( x => x.DeletedAt == null )
.OrderBy( x => x.GeoLocation.Distance( geo ) );
...
}
Run Code Online (Sandbox Code Playgroud)
这很好
private IQueryable<Field> PrepareAllFieldsQuery( DbGeography geo, int page, int amount, string sort, string order, ISearchCriteria searchCriteria )
{
var query = this.context.Fields
.Where( x => x.DeletedAt == null )
.OrderBy( x => x.GeoLocation.Distance( geo ) );
...
}
Run Code Online (Sandbox Code Playgroud)
不同的是这次我DbGeography没有通过ref.
.OrderBy( x => x.GeoLocation.Distance( geo ) );函数会抛出以下错误的任何原因:
无法将lambda表达式转换为类型'string',因为它不是委托类型
您收到的错误是由 C# 的重载解析所做的有趣的事情引起的...它试图将您解析为接受 a作为参数的OrderByDynamic Linq“版本” 。OrderBystring
一般来说,这是一个更正确的错误,如果您删除using System.Linq.Dynamic;或重写语句以强制使用Queryable.OrderBy,则会出现错误,例如:
var query = Queryable.OrderBy( this.context.Fields.Where( x => x.DeletedAt == null ),
x => x.GeoLocation.Distance( geo ) );
Run Code Online (Sandbox Code Playgroud)
将是Cannot use ref or outparameter 'geo' inside anonymous method, lambda expression, or query expression。正如 rdoubleui 所指出的,这里有一个解释。
| 归档时间: |
|
| 查看次数: |
3911 次 |
| 最近记录: |