C# WebAPI数据库永远挂起

C# WebAPI数据库永远挂起,c#,asp.net-web-api,spatial,C#,Asp.net Web Api,Spatial,我有一个实体-GeoEntity,它有一个DbGeography属性。在我的Web Api中,我有一个POST端点,允许您添加新的地理实体 实体- public class GeoEntity { [JsonProperty("point")] [NotMapped] public GeoPoint Point { get; set; } [JsonIgnore] public DbGeography Location { get { //

我有一个实体-GeoEntity,它有一个
DbGeography
属性。在我的Web Api中,我有一个POST端点,允许您添加新的地理实体

实体-

public class GeoEntity {

  [JsonProperty("point")]
  [NotMapped]
  public GeoPoint Point { get; set; }

  [JsonIgnore]
  public DbGeography Location {

    get 
    {
      // Breakpoint A
      return DbGeography.FromText($"POINT({Point.Longitude} {Point.Latitude})", 4326); 
    }

    set 
    {
      Point.Latitutde = value.Latitide;
      Point.Longitude = value.Longitude;
    }

  }

}

public class GeoPoint {

  public double Latitude { get; set; }

  public double Longitude { get; set; }

}
原料药-

我被困在断点A上。当我从该端点继续时,我从未到达断点B,http请求永远处于挂起状态

如果我试着越过,什么都不会发生

我已经将
从text
结果捕获到一个临时的
var x
,以确保它在尝试解析时没有陷入困境,并且可以肯定的是,它在尝试解析时没有陷入困境。DbGeography对象创建得很好

如果我在get中返回null:
get{returnnull;}
我确实到达了断点B
。但显然我的数据丢失了

知道为什么返回一个实际的
DbGeography
对象会导致请求永久挂起,而返回
null
则不会吗?

序列化程序出现问题 根据您的问题,
断点A
一开始就不应该被击中,因为您明确告诉序列化程序忽略它,而它显然没有这样做

很可能是您的序列化程序试图序列化类型为
DbGeography
的属性
Location

简单地说,您的序列化程序不会忽略它并尝试检索值以序列化它。基于你提供的装饰师,这不是你的意图

注:
根据序列化程序的不同,您需要使用以下属性/装饰器之一

 // using System.Web.Extensions;
 // using System.Web.Script.Serialization;

 [IgnoreDataMember]                  
 [ScriptIgnore]                      
 [JsonIgnore]
 public DbGeography Location { ... }
另一种选择是使用
DataContract
DataMember

[DataContract]
public class Computer
{
    // included in JSON
    [DataMember]
    public GeoPoint Point { get; set; }

    // ignored
    public DbGeography Location { get; set; }
}


如果出于任何原因,您正在尝试对其进行序列化。。。然后,您需要验证
DbGeography.FromText()
及其返回类型(
DbGeography
)的实现是否为对象实际上是“可序列化的”。

谢谢您,这些是类型示例代码不完整。提供一个可用于重现问题的。
 // using System.Web.Extensions;
 // using System.Web.Script.Serialization;

 [IgnoreDataMember]                  
 [ScriptIgnore]                      
 [JsonIgnore]
 public DbGeography Location { ... }
[DataContract]
public class Computer
{
    // included in JSON
    [DataMember]
    public GeoPoint Point { get; set; }

    // ignored
    public DbGeography Location { get; set; }
}