0
我想從LINQ查詢中獲取每個鍵值並將它們拉入我的視圖中。 LINQ查詢看起來是這樣的:從視圖中的LINQ查詢中選擇按鍵值
Public Property ByVDN As IEnumerable
Get
Dim valQ = (From scr In Var.db.CareSideA.ScriptCrossReferences
Join s In Var.db.CareSideA.Scripts On s.ScriptID Equals scr.ScriptID
Join ms In Var.db.CareSideA.MasterScripts On s.MasterScriptID Equals ms.MasterScriptID
Join svce In Var.db.CareSideA.Services On svce.SkillTargetID Equals scr.ForeignKey
Join p In Var.db.CareSideA.Peripherals On svce.PeripheralID Equals p.PeripheralID
Join sm In Var.db.CareSideA.ServiceMembers On svce.SkillTargetID Equals sm.ServiceSkillTargetID
Join sg In Var.db.CareSideA.SkillGroups On sm.SkillGroupSkillTargetID Equals sg.SkillTargetID
Where s.Version = ms.CurrentVersion And scr.TargetType = 1 And svce.PeripheralNumber = Value
Select New With {Key .Service = svce.PeripheralNumber,
Key .ScriptName = ms.EnterpriseName,
Key .Peripheral = p.EnterpriseName,
Key .SkillMapping = sg.PeripheralNumber,
Key .LatestVersion = s.Version,
Key .Created = s.DateTime,
Key .Author = s.Author}).ToList
Return valQ
End Get
Set(value As IEnumerable)
End Set
End Property
現在,這確實返回的結果,但他們看起來是這樣的:
理想情況下,我想能夠做到這一點:
<table>
For Each Item In Model.ByVDN
Dim i = Item
<tr>
<td>@Html.DisplayFor(Function(m) i.Service)</td>
<td>@Html.DisplayFor(Function(m) i.ScriptName)</td>
<td>@Html.DisplayFor(Function(m) i.Peripheral)</td>
Next
等...
你會認爲他們會想出一個不那麼單調乏味方法... – aaronmallen
在過去的2年,MVC工作我來的結論,這是值得的努力爲每個視圖創建視圖模型。特別是如果應用程序做了非基本的事情,並且您打算進一步開發它。 – trailmax
我完全同意。這正是我要做的,但是我們在2月份之前凍結了一個代碼。並且在這之前我無法將新視圖推送到我們的SQL服務器「/ – aaronmallen