var result =
from ap in db.Appraisals
join at in db.AppraisalTypes
on ap.AppraisalType_ID equals at.AppraisalType_ID
join w in db.Workers
on ap.Worker_ID equals w.Worker_ID
where ap.Worker_ID == WorkerID
&& ap.DateDue != null
&& ap.DateCompleted == null
select new
{
ap.Worker_ID,
ap.Appraisal_ID,
at.Description,
ap.DateDue,
ap.DateCompleted,
CompletedBy = from ap2 in db.Appraisals
join w2 in db.Workers
on ap2.CompletedBy equals w2.Worker_ID
select new
{
name = w2.Surname + ", " + w2.FirstName
}
};
工作正如你可能會看到我使用兩個工作目標,其中之一是是有其年度/中期就業評價和職工其他對象是他們的直線經理。
此選擇用於綁定摘要列表視圖控件,但在我試圖分配的CompletedBy列上始終將最新的條目設置爲空,那麼歷史數據將填充行管理器名稱評估工作已經完成。我已經在這個問題上做了一個快速搜索,並且有許多帖子有答案,但我作爲一名開發人員並不是非常有經驗,並且正在尋找一個簡單的答案。我的另一個擔心是,我想分配一個列,我知道列表中總是有一個空值。
雖然編譯器可以識別這爲語法正確的,在我的綁定標籤文本屬性有以下...
System.Collections.Generic.List`1[<>f__AnonymousType9`1[System.String]]
我只是在尋找任何可能的警告我在這裏建設並填寫我對LINQ的知識非常有限。
<asp:ListView ID="lvwProbations" runat="server"
OnSelectedIndexChanged="lvwProbations_SelectedIndexChanged"
OnPagePropertiesChanged="lvwProbations_PagePropertiesChanged"
OnPagePropertiesChanging="lvwProbations_PagePropertiesChanging"
DataKeyNames="Worker_ID,Appraisal_ID">
<ItemTemplate>
<tr class="tableItemStyle"
onmouseover="this.style.backgroundColor='Silver'"
onmouseout="this.style.backgroundColor='#EAFFFF'">
<td>
<asp:Label ID="lblWorkerID" runat="server"
Text='<%# Bind("Worker_ID") %>' Visible="false" />
</td>
<td>
<asp:Label ID="lblProbation" runat="server" Width="200"
Text='<%# Bind("Description") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateDue" runat="server" Width="100"
Text='<%# Bind("DateDue", "{0:d}") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateCompleted" runat="server" Width="100"
Text='<%# Bind("DateCompleted") %>' />
</td>
<td align="center">
<asp:Label ID="lblCompletedBy" runat="server" Width="100"
Text='<%# Bind("CompletedBy") %>' />
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server"
SkinID="selecttimesheet" CommandName="Select" />
</td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr class="tableAlternatingItemStyle"
onmouseover="this.style.backgroundColor='Silver'"
onmouseout="this.style.backgroundColor='#CCFFFF'">
<td>
<asp:Label ID="lblWorkerID" runat="server"
Text='<%# Bind("Worker_ID") %>' Visible="false" />
</td>
<td>
<asp:Label ID="lblProbation" runat="server" Width="200"
Text='<%# Bind("Description") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateDue" runat="server" Width="100"
Text='<%# Bind("DateDue", "{0:d}") %>' />
</td>
<td align="center">
<asp:Label ID="lblDateCompleted" runat="server" Width="100"
Text='<%# Bind("DateCompleted") %>' />
</td>
<td align="center">
<asp:Label ID="lblCompletedBy" runat="server" Width="100"
Text='<%# Bind("CompletedBy") %>' />
</td>
<td>
<asp:ImageButton ID="btnSelect" runat="server"
SkinID="selecttimesheet" CommandName="select" />
</td>
</tr>
</AlternatingItemTemplate>
<EmptyDataTemplate>
<table id="Table1" runat="server" style="">
<tr id="Tr2" runat="server" class="tableHoursHeaderStyle">
<th id="Th1" runat="server" style="width:0px;"></th>
<th id="Th2" runat="server">Appraisal</th>
<th id="Th3" runat="server">Date Due</th>
<th id="Th13" runat="server">Date Completed</th>
<th id="Th4" runat="server">Completed By</th>
<th id="Th6" runat="server" style="width:0px;"></th>
</tr>
<tr>
<td colspan="4">
<p>No Probations available</p>
</td>
</tr>
</table>
</EmptyDataTemplate>
<LayoutTemplate>
<table id="Table2" runat="server">
<tr id="Tr1" runat="server">
<td id="Td1" runat="server">
<table ID="itemPlaceholderContainer" runat="server"
border="0" class="TimeSheet_Table" style="">
<tr id="Tr2" runat="server"
class="tableHoursHeaderStyle">
<th id="Th1" runat="server" style="width:0px;"></th>
<th id="Th2" runat="server">Appraisal</th>
<th id="Th3" runat="server">Date Due</th>
<th id="Th13" runat="server">Date Completed</th>
<th id="Th5" runat="server">Completed By</th>
<th id="Th7" runat="server" style="width:0px;"></th>
</tr>
<tr ID="itemPlaceholder" runat="server"></tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:ListView>
編輯,以顯示要求
不知道問題是什麼,你能更清楚了嗎? – Maghis
道歉,基本上嵌套選擇綁定System.Collections代碼片段如上。我需要獲得直線經理的名字,因爲每次對特定員工的最新評估都會對CompletedBy字段返回空值。代碼片段的含義是什麼?我對於返回數據記錄/列的嘗試有何不瞭解? – dotnetnewb
讓我看看你的標籤綁定。 – WinnerIT