0

我有一个数据库模式如下:

FailureItem
---------------
FailureID int foreign key references Failure (FailureID)
DatabaseID int NULL foreign key references Items (DatabaseID)
FailureDescription varchar(200)

Item
---------------
DatabaseID int primary key identity(1,1)
ItemDescription varchar(200)

我正在使用 linq 将其绑定到 gridview,如下所示:

Dim items as List(Of FailureItems) =
    context.FailureItems.include("Item").where(function(x) x.FailureID = _failureID)



<asp:GridView ID="gv1" runat="server">
    <Columns>
        <asp:BoundField DataField="databaseID" Visible="false" />
        <asp:BoundField DataField="FailureDescription" headertext="Failure Description" />
        <asp:BoundField DataField="Item.ItemDescription" headertext="Item Description" />
    </Columns>
</asp:GridView>

这在我的开发机器上完美运行。当我将它发布到 azure 上时,我收到错误“在所选数据源上找不到名为 'Item.ItemDescription' 的字段或属性”。我究竟做错了什么?

4

1 回答 1

0

我最终将代码更改为以下内容,这很有效:

Dim items =
    (from fi in context.FailureItems
     where(fi.FailureID = _failureID)
     select new with {
         fi.databaseID,
         fi.FailureDescription,
         ItemDescription = If(fi.Item isnot nothing, fi.Item.ItemDescription, nothing)
     }).ToList
于 2012-11-29T16:05:11.767 回答