首页 > 解决方案 > ASP.NET MVC 和实体框架问题

问题描述

我创建了一个小型学习项目来使用 Cdata 实用程序读取和写入 CRM。

我创建了一个模型、控制器和视图,但是在尝试查看索引页面时,我不断收到错误消息

new_accountactive 不是有效字段

我已经检查并仔细检查了 CRM 系统和 SQL 数据库。寻找有关我哪里出错的指导。

' GET: OriginatingAccounts (controller ) 
Function Index() As ActionResult
Private db As New DynamicsCRMContext
Dim _list = db.OriginatingAccounts.SqlQuery("SELECT id, new_accountserial, new_sun, new_sortcode, new_accountnumber, new_accountname  
                                             FROM new_oaccounts  
                                             WHERE new_accountactive = true").ToList

 Return View(_list)
 End Function

模型

Imports System.ComponentModel.DataAnnotations
Imports System.ComponentModel.DataAnnotations.Schema

<Table("new_oaccounts")>
Public Class OriginatingAccounts
<Key>
<Display(Name:="Account ID")>
Public Property Id As String
'<Display(Name:="Licence")>
'Public Property new_licenceid As String
<Display(Name:="Account Serial")>
Public Property new_accountserial As String
<Display(Name:="SUN")>
Public Property new_sun As String
<Display(Name:="Sort Code")>
Public Property new_sortcode As String
<Display(Name:="Account Number")>
Public Property new_accountnumber As String
<Display(Name:="Account Name")>
Public Property new_accountname As String

<Display(Name:="Active")>
Public Property new_accountactive As Nullable(Of Boolean)

<Display(Name:="Credit Account")>
Public Property new_creditingaccount As Boolean

<Display(Name:="Debit Account")>
Public Property new_debitingaccount As Boolean

<Display(Name:="SUN Validated")>
Public Property new_validated As Boolean
End Class

索引视图

ModelType IEnumerable(Of TestProject.OriginatingAccounts)
@Code
ViewData("Title") = "Index"
Layout = "~/Views/Shared/_Layout.vbhtml"
End Code

<h2>Originating Accounts</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<h4>Active Originating Accounts</h4>

<tr>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_accountserial)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_sun)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_sortcode)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_accountnumber)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_accountname)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_accountactive)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_creditingaccount)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_debitingaccount)
    </th>
    <th>
        @Html.DisplayNameFor(Function(model) model.new_validated)
    </th>
    <th></th>
</tr>

@For Each item In (Model.Where(Function(w) w.new_validated = True))
    @<tr>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_accountserial)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_sun)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_sortcode)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_accountnumber)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_accountname)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_accountactive)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_creditingaccount)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_debitingaccount)
        </td>
        <td>
            @Html.DisplayFor(Function(modelItem) item.new_validated)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", New With {.id = item.Id}) |
            @Html.ActionLink("Details", "Details", New With {.id = item.Id}) |
            @Html.ActionLink("Delete", "Delete", New With {.id = item.Id})
        </td>
    </tr>
Next
</table>

标签: asp.net-mvcvb.netentity-framework

解决方案


推荐阅读