重新配置Linq查询以创建对象:LINQ to Entities无法识别该方法

时间:2019-06-16 22:25:36

标签: c# linq linq-to-entities

我有以下查询,它们返回一组新对象:

  _MapData.features = (from gs in QBEntities.GeoStates
                       select new MapDataRecord()
                       {
                         properties = new MapDataRecordProperties()
                                      {
                                        GEOID = gs.GEOID,
                                        GEO_NAME = gs.GEO_NAME
                                      },
                         geometry = SetGeoJsonGeography(gs.GEO_OBJECT.SpatialTypeName, gs.JSON_GEOMETRY)
                       }
                      ).ToList();

但是SetGeoJsonGeography()出现问题,我收到错误消息:“ LINQ to Entities无法识别该方法”

在创建几何图形之前,需要先弄清楚几何图形的类型,以便可以选择正确的数组类型。

方法:

private MapDataGeometry SetGeoJsonGeography(string GeographyType, string GeoJsonGeographyString)
{
  if (GeographyType.Equals("polygon", StringComparison.CurrentCultureIgnoreCase))
  {
    return new MapDataPolygon() { type = GeographyType, coordinates = Newtonsoft.Json.JsonConvert.DeserializeObject<double[][][]>(GeoJsonGeographyString) };
  }
  else if (GeographyType.Equals("multipolygon", StringComparison.CurrentCultureIgnoreCase))
  {
    return new MapDataMultiPolygon() { type = GeographyType, coordinates = Newtonsoft.Json.JsonConvert.DeserializeObject<double[][][][]>(GeoJsonGeographyString) };
  }
  else
  {
    return null;
  }
}

以下是课程:

  [Serializable]
  public class MapDataGeometry
  {
    public string type { get; set; }
  }

  [Serializable]
  public class MapDataPolygon : MapDataGeometry
  {
    public double[][][] coordinates { get; set; }
  }

  [Serializable]
  public class MapDataMultiPolygon : MapDataGeometry
  {
    public double[][][][] coordinates { get; set; }
  }

我该如何实现?

1 个答案:

答案 0 :(得分:1)

您的方法无法转移到您的sql提供程序。 您应该先获取原始数据,然后再执行您的方法。

resp.json()