看着这个:
var t = ctx.Layer
.Where(c => c.Geometry.Intersects(boundingBox))
.Select(s => new
{
Geometry = SqlSpatialFunctions.Reduce(s.Geometry, degreesPerPixel),
s.column1,
s.column2,
s.column3,
s.column4,
s.column5,
s.column6,
s.column7,
s.column8,
s.column9,
}).ToArray();
相当恼人的是,为了在列上运行函数,必须再次编写所有列。有更好的方法吗?
答案 0 :(得分:1)
“更好”,无需编写所有属性:
var t = ctx.Layer
.Where(c => c.Geometry.Intersects(boundingBox))
.Select(s => new
{
Geometry = SqlSpatialFunctions.Reduce(s.Geometry, degreesPerPixel),
Layer = s
}).ToArray();
答案 1 :(得分:0)
继承人我的所作所为。非常类似于Eren的答案。
public static class VectorLayerHelperExtensions
{
public static IEnumerable<OgrEntity> Reduce(this IQueryable<OgrEntity> query, double threshold)
{
return query.Select(s => new
{
g = SqlSpatialFunctions.Reduce(s.Geometry, threshold),
s
}).AsEnumerable().Select(t => { t.s.Geometry = t.g; return t.s; });
}
}