列名无效 - 但不是

时间:2012-07-26 18:34:00

标签: c# .net database entity-framework razor

我收到了一个"无效的列"我尝试查看在WebGrid中显示产品数据的网页时出错。

我目前正在运行完全相同代码的实时版本。但是,此本地版本不适用于此特定页面。

enter image description here

如您所见,下图中引用的代码完全匹配错误消息下方描述的列名称。

我完全难过了。我不知道现在该做什么。它告诉我"无效栏",但它不是。它在那里,我三重检查我的代码中的任何拼写错误(在下面),一切都很好!

是什么给出了?

<div id="grid">
  @grid.GetHtml(
    headerStyle : "HeaderStyle",
    columns: grid.Columns(
      grid.Column(
        columnName : "PartNumber",
        header : "Part Number",
        style : "PartNumberStyle"
      ),
      grid.Column(
        columnName : "Product",
        header : "Description"
      ),
      grid.Column(
        columnName : "Quantity",
        header : "Quantity"
      ),
      grid.Column(
        columnName : "ZincPlatedCL2UnitPrice",
        header : "Zinc Plated CL2 Unit Price",
        format: @<a href="?Action=Add&PartNumber=@item["PartNumber"]&Product=@item["Product"]&Type=Zinc Plated CL2 Unit Price&Units=1&UnitPrice=@item["ZincPlatedCL2UnitPrice"]&IsBoxed=0">@item["ZincPlatedCL2UnitPrice"]</a>
      ),
      grid.Column(
        columnName : "ZincPlatedCL2BoxPrice",
        header : "Zinc Plated CL2 Box Price",
        format: @<a href="?Action=Add&PartNumber=@item["PartNumber"]&Product=@item["Product"]&Type=Zinc Plated CL2 Box Price&Units=1&BoxPrice=@item["ZincPlatedCL2BoxPrice"]&IsBoxed=1">@item["ZincPlatedCL2BoxPrice"]</a>
      )
    )
  )
</div>
堆栈跟踪
  

[InvalidOperationException:列名无效   &#34; ZincPlatedCL2UnitPrice&#34 ;.]
  WebMatrix.Data.DynamicRecord.VerifyColumn(String name)+17193
  WebMatrix.Data.DynamicRecord.get_Item(String name)+17
  WebMatrix.Data.DynamicRecord.TryGetMember(GetMemberBinder binder,   对象和放大器;结果)+7 CallSite.Target(Closure,CallSite,Object)   +140 System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site,T0 arg0)+432
  Microsoft.Internal.Web.Utils.DynamicHelper.GetMemberValue(Object obj,   String memberName)+26
  Microsoft.Internal.Web.Utils.DynamicHelper.TryGetMemberValue(对象   obj,String memberName,Object&amp;结果)+24
  System.Web.Helpers.WebGridRow.TryGetMember(String memberName,Object&amp;   结果)+57 System.Web.Helpers.WebGridRow.get_Item(String name)+58   CallSite.Target(Closure,CallSite,Object,String)+100
  System.Dynamic.UpdateDelegates.UpdateAndExecute2(CallSite site,T0   arg0,T1 arg1)+685
  ASP&LT;&GT; c__DisplayClass1f.b__1c(TextWriter的   __razor_template_writer)在c:\ Users \ Jase \ Documents \ Visual Studio 2012 \ WebSites \ One Stop中   紧固件\共享\产品\ TekScrews \ SelfDrillingMetalUseCL2.cshtml:98   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)+10
  System.Web.Helpers。&lt;&gt; c__DisplayClass10.b__f(TextWriter tw)+42   System.Web.WebPages.HelperResult.ToString()+82
  System.Web.Helpers&LT;&GT; c__DisplayClass4.b__3(TextWriter的   __razor_helper_writer)+1444 System.Web.WebPages.HelperResult.ToString()+82
  System.Web.WebPages.HelperResult.ToHtmlString()+9
  System.Web.HttpUtility.HtmlEncode(Object value)+38
  System.Web.WebPages.WebPageBase.Write(Object value)+68
  ASP._Page_Shared_Products_TekScrews_SelfDrillingMetalUseCL2_cshtml.Execute()   在c:\ Users \ Jase \ Documents \ Visual Studio 2012 \ WebSites \ One Stop中   紧固件\共享\产品\ TekScrews \ SelfDrillingMetalUseCL2.cshtml:82   System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+197
  System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1   执行者)+69 System.Web.WebPages.WebPage.ExecutePageHierarchy()   +151 System.Web.WebPages.StartPage.RunPage()+ 17 System.Web.WebPages.StartPage.ExecutePageHierarchy()+62
  System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext   pageContext,TextWriter writer,WebPageRenderingBase startPage)+76
  System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase   httpContext)+114

     

----------------------------------------------- ---------------------------------版本信息:Microsoft .NET Framework版本:4.0.30319;   ASP.NET版本:4.0.30319.17626堆栈跟踪:

     

[InvalidOperationException:列名无效   &#34; ZincPlatedCL2UnitPrice&#34 ;.]
  WebMatrix.Data.DynamicRecord.VerifyColumn(String name)+17193
  WebMatrix.Data.DynamicRecord.get_Item(String name)+17
  WebMatrix.Data.DynamicRecord.TryGetMember(GetMemberBinder binder,   对象和放大器;结果)+7 CallSite.Target(Closure,CallSite,Object)   +140 System.Dynamic.UpdateDelegates.UpdateAndExecute1(CallSite site,T0 arg0)+432
  Microsoft.Internal.Web.Utils.DynamicHelper.GetMemberValue(Object obj,   String memberName)+26
  Microsoft.Internal.Web.Utils.DynamicHelper.TryGetMemberValue(对象   obj,String memberName,Object&amp;结果)+24
  System.Web.Helpers.WebGridRow.TryGetMember(String memberName,Object&amp;   结果)+57 System.Web.Helpers.WebGridRow.get_Item(String name)+58   CallSite.Target(Closure,CallSite,Object,String)+100
  System.Dynamic.UpdateDelegates.UpdateAndExecute2(CallSite site,T0   arg0,T1 arg1)+685
  ASP&LT;&GT; c__DisplayClass1f.b__1c(TextWriter的   __razor_template_writer)在c:\ Users \ Jase \ Documents \ Visual Studio 2012 \ WebSites \ NameRemoved \ Shared \ Products \ TekScrews \ SelfDrillingMetalUseCL2.cshtml:98   System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)+10
  System.Web.Helpers。&lt;&gt; c__DisplayClass10.b__f(TextWriter tw)+42   System.Web.WebPages.HelperResult.ToString()+82
  System.Web.Helpers&LT;&GT; c__DisplayClass4.b__3(TextWriter的   __razor_helper_writer)+1444 System.Web.WebPages.HelperResult.ToString()+82
  System.Web.WebPages.HelperResult.ToHtmlString()+9
  System.Web.HttpUtility.HtmlEncode(Object value)+38
  System.Web.WebPages.WebPageBase.Write(Object value)+68
  ASP._Page_Shared_Products_TekScrews_SelfDrillingMetalUseCL2_cshtml.Execute()   在c:\ Users \ Jase \ Documents \ Visual Studio中   2012 \网站已\ NameRemoved \共享\产品\ TekScrews \ SelfDrillingMetalUseCL2.cshtml:82   System.Web.WebPages.WebPageBase.ExecutePageHierarchy()+197
  System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1   执行者)+69 System.Web.WebPages.WebPage.ExecutePageHierarchy()   +151 System.Web.WebPages.StartPage.RunPage()+ 17 System.Web.WebPages.StartPage.ExecutePageHierarchy()+62
  System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext   pageContext,TextWriter writer,WebPageRenderingBase startPage)+76
  System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase   httpContext)+114

     

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

更新日期:27/07/2012


调试时,异常指向这行代码:

format: @<a href="?Action=Add&PartNumber=@item["PartNumber"]&Product=@item["Product"]&Type=Zinc Plated CL2 Unit Price&Units=1&UnitPrice=@item["ZincPlatedCL2UnitPrice"]&IsBoxed=0">@item["ZincPlatedCL2UnitPrice"]</a>

enter image description here

1 个答案:

答案 0 :(得分:2)

您是否确实已检查过本地数据库以确保该列位于架构中?与您的实体框架架构相比,您的本地数据库可能“旧”。