我有一个数据库模式如下:
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'的字段或属性。”我做错了什么?
答案 0 :(得分: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