Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC给出了错误;没有为此对象定义无参数构造函数“;对于System.Data.Entity.Spatial.DbGeography_C#_Asp.net_Asp.net Mvc_Visual Studio - Fatal编程技术网

C# MVC给出了错误;没有为此对象定义无参数构造函数“;对于System.Data.Entity.Spatial.DbGeography

C# MVC给出了错误;没有为此对象定义无参数构造函数“;对于System.Data.Entity.Spatial.DbGeography,c#,asp.net,asp.net-mvc,visual-studio,C#,Asp.net,Asp.net Mvc,Visual Studio,我得到一个错误,关于没有为System.Data.Entity.Spatial.DbGeography找到无参数构造函数: [MissingMethodException:没有为此定义无参数构造函数 object.object类型“System.Data.Entity.Spatial.DbGeography”。] 我首先使用数据库中的代码。我所有的其他实体都很好,这是唯一一个有问题的 控制器采用MVC5脚手架制造 我错过了什么或做错了什么 namespace Delivery.Mode

我得到一个错误,关于没有为System.Data.Entity.Spatial.DbGeography找到无参数构造函数:

[MissingMethodException:没有为此定义无参数构造函数 object.object类型“System.Data.Entity.Spatial.DbGeography”。]

我首先使用数据库中的代码。我所有的其他实体都很好,这是唯一一个有问题的

控制器采用MVC5脚手架制造

我错过了什么或做错了什么

     namespace Delivery.Models.BaseModels
     {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Data.Entity.Spatial;

    public partial class RestaurantProfile
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public RestaurantProfile()
        {
            AspNetUsers = new HashSet<AspNetUser>();
            Orders = new HashSet<Order>();
        }

        [Key]
        public Guid RestaurantPofileID { get; set; }

        [StringLength(250)]
        public string Name { get; set; }

        public string LocationName { get; set; }

        public DbGeography LocationGPS { get; set; }

        public decimal? DeliveryFee1 { get; set; }

        public decimal? DeliveryFee2 { get; set; }

        public decimal? DeliveryFee3 { get; set; }

        [Column(TypeName = "datetime2")]
        public DateTime CreatedDate { get; set; }

        [Column(TypeName = "datetime2")]
        public DateTime ModifyDate { get; set; }

        public string Notes { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<AspNetUser> AspNetUsers { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<Order> Orders { get; set; }

    }
    }
        using System;
        using System.Collections.Generic;
        using System.Data;
         using System.Data.Entity;
     using System.Linq;
     using System.Net;
     using System.Web;
     using System.Web.Mvc;
     using Delivery.Models.BaseModels;

    namespace Delivery.Controllers
  {
    public class RestaurantProfilesController : Controller
    {
        private DeliveryEntities db = new DeliveryEntities();

        // GET: RestaurantProfiles
        public ActionResult Index()
        {
            return View(db.RestaurantProfiles.ToList());
        }

        // GET: RestaurantProfiles/Details/5
        public ActionResult Details(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            RestaurantProfile restaurantProfile = db.RestaurantProfiles.Find(id);
            if (restaurantProfile == null)
            {
                return HttpNotFound();
            }
            return View(restaurantProfile);
        }

        // GET: RestaurantProfiles/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: RestaurantProfiles/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "RestaurantPofileID,Name,LocationName,LocationGPS,DeliveryFee1,DeliveryFee2,DeliveryFee3,CreatedDate,ModifyDate,Notes")] RestaurantProfile restaurantProfile)
        {
            if (ModelState.IsValid)
            {
                restaurantProfile.RestaurantPofileID = Guid.NewGuid();
                db.RestaurantProfiles.Add(restaurantProfile);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(restaurantProfile);
        }

        // GET: RestaurantProfiles/Edit/5
        public ActionResult Edit(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            RestaurantProfile restaurantProfile = db.RestaurantProfiles.Find(id);
            if (restaurantProfile == null)
            {
                return HttpNotFound();
            }
            return View(restaurantProfile);
        }

        // POST: RestaurantProfiles/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include = "RestaurantPofileID,Name,LocationName,LocationGPS,DeliveryFee1,DeliveryFee2,DeliveryFee3,CreatedDate,ModifyDate,Notes")] RestaurantProfile restaurantProfile)
        {
            if (ModelState.IsValid)
            {
                db.Entry(restaurantProfile).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(restaurantProfile);
        }

        // GET: RestaurantProfiles/Delete/5
        public ActionResult Delete(Guid? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            RestaurantProfile restaurantProfile = db.RestaurantProfiles.Find(id);
            if (restaurantProfile == null)
            {
                return HttpNotFound();
            }
            return View(restaurantProfile);
        }

        // POST: RestaurantProfiles/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(Guid id)
        {
            RestaurantProfile restaurantProfile = db.RestaurantProfiles.Find(id);
            db.RestaurantProfiles.Remove(restaurantProfile);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
    }
namespace Delivery.Models.BaseModels
{
使用制度;
使用System.Collections.Generic;
使用System.ComponentModel.DataAnnotations;
使用System.ComponentModel.DataAnnotations.Schema;
使用System.Data.Entity.Spatial;
公共部分类RestaurantProfile
{
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2214:DoNotCallOverridableMethodsInConstructors”)]
公共餐厅档案()
{
AspNetUsers=newhashset();
Orders=新HashSet();
}
[关键]
公共Guid RestaurantProfileId{get;set;}
[长度(250)]
公共字符串名称{get;set;}
公共字符串位置名称{get;set;}
公共数据库地理位置GPS{get;set;}
公共十进制?DeliveryFee1{get;set;}
公共十进制?DeliveryFee2{get;set;}
公共十进制?DeliveryFee3{get;set;}
[列(TypeName=“datetime2”)]
公共日期时间CreatedDate{get;set;}
[列(TypeName=“datetime2”)]
公共日期时间修改日期{get;set;}
公共字符串注释{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection AspNetUsers{get;set;}
[System.Diagnostics.CodeAnalysis.SuppressMessage(“Microsoft.Usage”,“CA2227:CollectionPropertiesShouldBreadOnly”)]
公共虚拟ICollection订单{get;set;}
}
}
使用制度;
使用System.Collections.Generic;
使用系统数据;
使用System.Data.Entity;
使用System.Linq;
Net系统;
使用System.Web;
使用System.Web.Mvc;
使用Delivery.Models.BaseModels;
命名空间传递.控制器
{
公共类RestaurantProfilesController:控制器
{
private DeliveryEntities db=新的DeliveryEntities();
//获取:RestaurantProfiles
公共行动结果索引()
{
返回视图(db.RestaurantProfiles.ToList());
}
//获取:RestaurantProfiles/Details/5
公共操作结果详细信息(Guid?id)
{
if(id==null)
{
返回新的HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
RestaurantProfile RestaurantProfile=db.RestaurantProfile.Find(id);
if(restaurantProfile==null)
{
返回HttpNotFound();
}
返回视图(restaurantProfile);
}
//获取:RestaurantProfiles/创建
公共操作结果创建()
{
返回视图();
}
//发布:RestaurantProfiles/Create
//若要防止套印攻击,请启用要绑定到的特定属性,例如
//更多详细信息请参见https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
公共操作结果创建([Bind(包括=“RestaurantProfileId、名称、位置名称、位置GPS、DeliveryFee1、DeliveryFee2、DeliveryFee3、CreatedDate、ModifyDate、Notes”)]RestaurantProfile RestaurantProfile
{
if(ModelState.IsValid)
{
restaurantProfile.RestaurantProfileId=Guid.NewGuid();
db.restaurantProfile.Add(restaurantProfile);
db.SaveChanges();
返回操作(“索引”);
}
返回视图(restaurantProfile);
}
//获取:RestaurantProfiles/Edit/5
公共操作结果编辑(Guid?id)
{
if(id==null)
{
返回新的HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
RestaurantProfile RestaurantProfile=db.RestaurantProfile.Find(id);
if(restaurantProfile==null)
{
返回HttpNotFound();
}
返回视图(restaurantProfile);
}
//发布:RestaurantProfiles/Edit/5
//若要防止套印攻击,请启用要绑定到的特定属性,例如
//更多详细信息请参见https://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
公共操作结果编辑([Bind(包括=“RestaurantProfileId,Name,LocationName,LocationGPS,DeliveryFee1,DeliveryFee2,DeliveryFee3,CreatedDate,ModifyDate,Notes”)]RestaurantProfile RestaurantProfile
{
if(ModelState.IsValid)
{
db.Entry(restaurantProfile).State=EntityState.Modified;
db.SaveChanges();
返回操作(“索引”);
}
返回视图(restaurantProfile);
}
//获取:RestaurantProfiles/Delete/5
公共操作结果删除(Guid?id)
{
if(id==null)
{
返回新的HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
RestaurantProfile RestaurantProfile=db.RestaurantProfile.Find(id);
if(restaurantProfile==null)
{
返回HttpNotFound();
}
返回视图(restaurantProfile);
}
//发布:RestaurantProfiles/Delete/5
[HttpPost,ActionName(“删除”)]
[Val]
[MissingMethodException: No parameterless constructor defined for this object.]
   System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
   System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +119
   System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +247
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
   System.Activator.CreateInstance(Type type) +11
   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +197

[MissingMethodException: No parameterless constructor defined for this object. Object type 'System.Data.Entity.Spatial.DbGeography'.]
   System.Web.Mvc.DefaultModelBinder.CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType) +233
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +530
   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +330
   System.Web.Mvc.DefaultModelBinder.GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder) +17
   System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +377
   System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +101
   System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +55
   System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1197
   System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +330
   System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +338
   System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +105
   System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__19(AsyncCallback asyncCallback, Object asyncState) +743
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +14
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +343
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +25
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +465
   System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +18
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +20
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +374
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +16
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +52
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +30
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +128
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +384
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +443
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +157