System.Data.SqlClient.SqlException:列名无效' Faculty_Id'

时间:2016-04-30 16:45:19

标签: asp.net-mvc-4 entity-framework-4

控制器:

public async Task<ActionResult> Create([Bind(Include = "Id,Terms,Semester,Sections,Course,CreditHourTheory,CreditHourLab,Labinstructor,Faculty,Rooms,Day,Date,TimeStart,TimeEnd")] TimeTable.Models.TimeTable timetable)    
    {

        if (ModelState.IsValid)
        {
            db.TimeTable.Add(timetable);
            await db.SaveChangesAsync();
            return RedirectToAction("Create");
        }
        return View(timetable);

    }

在视图中,我使用下拉列表从数据库中获取值并将此选定值插入数据库中的另一个表中

@Html.DropDownList("FId", null, String.Empty, new { @class = "form-control input-md cc2", @disabled = "disabled", @required = "" })

型号:

[Table("TimeTable")]
public class TimeTable
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public string Terms { get; set; }
    public string Semester { get; set; }


    public int SectionsId { get; set; }

    [ForeignKey("SectionsId")]
    public Sections Sections { get; set; }

    public int CourseId { get; set; }

    [ForeignKey("CourseId")]
    public Course Course { get; set; }

    public string CreditHourTheory { get; set; }

    public string CreditHourLab { get; set; }

    public int? LabInstructorId { get; set; }
    [ForeignKey("LabInstructorId")]
    public Faculty Labinstructor { get; set; }

    public int FacultyId { get; set; }
    [ForeignKey("FacultyId")]
    public Faculty Faculty { get; set; }

    public int RoomId { get; set; }
    [ForeignKey("RoomId")]
    public Rooms Rooms { get; set; }


    public string Day { get; set; }

    public DateTime Date { get; set; }

    public TimeSpan TimeStart { get; set; }

    public TimeSpan TimeEnd { get; set; }
}

&#39; /&#39;中的服务器错误应用

列名称无效&#39; Faculty_Id&#39;。 描述:执行当前Web请求期间发生未处理的异常。请查看堆栈跟踪,以获取有关错误及其在代码中的起源位置的更多信息。

异常详细信息:System.Data.SqlClient.SqlException:列名无效&#39; Faculty_Id&#39;。

来源错误:

第54行:{

第55行:db.TimeTable.Add(时间表);

第56行:等待db.SaveChangesAsync();

第57行:返回RedirectToAction(&#34;创建&#34;);

第58行:}

源文件:c:\ Users \ NoorMuhammad \ Documents \ Visual Studio 2013 \ Projects \ TimeTable \ TimeTable \ Controllers \ HomeController.cs Line:56

堆栈追踪:

[SqlException(0x80131904):列名无效&#39; Faculty_Id&#39;。]    System.Data.SqlClient.SqlCommand.b__24(任务1 result) +1792654 System.Threading.Tasks.ContinuationResultTaskFromResultTask 2.InnerInvoke()+81    System.Threading.Tasks.Task.Execute()+45    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+93    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+52    System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +24 System.Data.Entity.Utilities.CultureAwaiter 1.GetResult()+123    System.Data.Entity.Core.Mapping.Update.Internal.d__0.MoveNext()+1068    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+93    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+52    System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +24 System.Data.Entity.Utilities.CultureAwaiter 1.GetResult()+71    System.Data.Entity.Core.Mapping.Update.Internal.d__0.MoveNext()+676

[UpdateException:更新条目时发生错误。有关详细信息,请参阅内部异常。]    System.Data.Entity.Core.Mapping.Update.Internal.d__0.MoveNext()+1044    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+93    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+52    System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +24 System.Data.Entity.Utilities.CultureAwaiter 1.GetResult()+66    System.Data.Entity.Core.Objects.d__3d 1.MoveNext() +1138 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter 1.GetResult()+24    System.Data.Entity.Utilities.CultureAwaiter 1.GetResult() +66 System.Data.Entity.Core.Objects.<SaveChangesToStoreAsync>d__39.MoveNext() +619 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.ConfiguredTaskAwaiter.GetResult() +24 System.Data.Entity.SqlServer.<ExecuteAsyncImplementation>d__9 1.MoveNext()+ 457    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+93    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+52    System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +24 System.Data.Entity.Utilities.CultureAwaiter 1.GetResult()+66    System.Data.Entity.Core.Objects.d__31.MoveNext()+1165

[DbUpdateException:更新条目时发生错误。有关详细信息,请参阅内部异常。]    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)+93    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)+52    System.Runtime.CompilerServices.TaskAwaiter 1.GetResult() +24 TimeTable.Controllers.<Create>d__8.MoveNext() in c:\Users\NoorMuhammad\Documents\Visual Studio 2013\Projects\TimeTable\TimeTable\Controllers\HomeController.cs:56 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52 System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21 System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +61 System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114 System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +66 System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult)+47    System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +136 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49 System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +117 System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323 System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323 System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +323 System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +44 System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult)+47    System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +136 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50 System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +72 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +185 System.Web.Mvc.Async.WrappedAsyncResult 1.CallEndDelegate(IAsyncResult asyncResult)+42    System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +133 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34 System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult)+70    System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +139 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +39 System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult)+62    System.Web.Mvc.Async.WrappedAsyncResultBase 1.End() +139 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39 System.Web.Mvc.Async.WrappedAsyncVoid 1.CallEndDelegate(IAsyncResult asyncResult)+70    System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+139    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+59    System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult,Object tag)+40    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)+40    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)+38    System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar)+129

版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.34274

0 个答案:

没有答案