I am building an app using the DotNetNuke 7 platform and am trying to write Geography data to the database. Here is some background on the project. I am building in VS 2012 and just upgraded to Server 2012 from 2008 R2. DotNetNuke 7 implements PetaPoco for the data layer and WebAPI.
I hope what I provided is enough to information to understand the problem. My code fails on the line "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);
}
}
}
}
Here is my object
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; }
}
}
I am passing in the Long and Lat from the client side from a Google map which gets the coords from a mouse click
In my database if I were to directly write an insert or update using the following, it will work.
geography:: STGeomFromText('POINT(-121.527200 45.712113)' , 4326);
What might be the reason?
-- though I would include a screen shot of the object