我正在使用DotNetNuke 7平台构建应用程序,并试图将Geography数据写入数据库。以下是该项目的一些背景。我在VS 2012中构建,刚刚从2008 R2升级到Server 2012。 DotNetNuke 7为数据层和WebAPI实现了PetaPoco。不存在从对象类型System.Data.Spatial.DbGeography到已知托管提供程序本机类型的映射
希望我提供的信息足以了解问题。我的代码在行“rep.Insert(location);”
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.Web;
using System.Net.Http;
using System.Web.Http;
using System.Data.Spatial;
using DotNetNuke.Web.Api;
using DotNetNuke.Data;
namespace DotNetNuke.Modules.GeoLocations
{
public class LocationController: DnnApiController
{
[AllowAnonymous]
[HttpPost]
[ValidateAntiForgeryToken]
public HttpResponseMessage addLocation(CP_Location submitted)
{
submitted.GeoCode = DbGeography.PointFromText(string.Format("POINT({0} {1})", submitted.Long, submitted.Lat), 4326);
createLocation(submitted);
return Request.CreateResponse(HttpStatusCode.OK, "Success");
}
//------------------------------CRUD------------------------------//
public void createLocation(CP_Location location)
{
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<CP_Location>();
rep.Insert(location);
}
}
}
}
这是我的目标
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Spatial;
using System.Data.Entity;
using DotNetNuke.ComponentModel.DataAnnotations;
using DotNetNuke.Data;
using DotNetNuke.Data.PetaPoco;
namespace DotNetNuke.Modules.GeoLocations
{
[TableName("CP_Locations")]
[PrimaryKey("LocationId", AutoIncrement = true)]
public class CP_Location
{
public int LocationId { get; set; }
public string LocationType { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public float Long { get; set; }
public float Lat { get; set; }
public DbGeography GeoCode { get; set; }
}
}
我在长和纬度通过从一个谷歌地图,从获取鼠标坐标中的客户端点击
在我的数据库中,如果我将直接编写插入或更新使用以下,它将工作。
geography:: STGeomFromText('POINT(-121.527200 45.712113)' , 4326);
可能是什么原因?
- 尽管我会包括对象
能否请您提供完整的异常详细信息(包括堆栈跟踪)的答案,正如它的toString()方法返回? – 2013-09-26 13:05:32