我在为新创建提交表单时遇到问题,我无法验证变量dbgeometry数据的问题..错误消息是“没有为此对象定义参数的构造函数”。 这是我的代码控制器:
var list = new List<Table1>()
{
new Table1(){ Column1="x", Column2="y", Column3= "z"},
new Table1(){ Column1="x", Column2="y", Column3= "t"},
new Table1(){ Column1="a", Column2="b", Column3= "c"},
};
var resulut = list.GroupBy(x => new { C1 = x.Column1, C2 = x.Column2 })
.Select(g => g.FirstOrDefault());
来自EF的我的模特:
[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);
}
答案 0 :(得分:0)
使用sqlQuery命令的最佳方式
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))");
它100%工作