1

I have a problem when submitting the form for a new creation, the problem that I can not validate the data of variable dbgeometry .. the error message is "No constructor without parameter defined for this object." this is my code controller :

    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Create([Bind(Include = "id,name,Location")] schoolinfo schoolinfo)
    {
        if (ModelState.IsValid)
        {
            db.schoolinfo.Add(schoolinfo);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        return View(schoolinfo);
    }

my model from EF :

public partial class schoolinfo
{
    public string id { get; set; }
    public string name { get; set; }
    public System.Data.Entity.Spatial.DbGeography Location { get; set; }
}
mason
  • 31,774
  • 10
  • 77
  • 121
oussama_tr
  • 61
  • 7

1 Answers1

0

the best way it's to use a sqlQuery command

var id = form["id"];
            var name = form["name"];
            var lat = form["Location.Latitude"];
            var lng = form["Location.Longitude"];
            db.Database.ExecuteSqlCommand("insert into [dbo].[schoolinfo] values ('" + id + "','" + name + "',geography::Point(" + lat + ", " + lng + ", 4326))");

it's 100% worked

oussama_tr
  • 61
  • 7