如何使用LinqToSql选择列AS



嗨,我有一个用户控件,它有一个中继器,该中继器绑定到两个表中的一个,这取决于用户控件中的参数集。这两个表有类似的数据,所以在过去我使用了一个SQL连接,并得到了这样的数据。

If m_Type = "STD" Then
   'Type is Standard so get data from S_Updates
   SQL="SELECT S_USER as User, S_Date as UDate, S_Update as Update FROM S_Updates WHERE S_Ref = " & m_caseRef & " ORDER By S_Date"
Else
   'Type is BSM so get data from B_Updates
   SQL="SELECT B_Device as User, B_Date as UDate, B_Update as Update FROM B_Updates WHERE B_Ref = " & m_caseRef & " ORDER By B_Date"
End If

然后,我将结果绑定到我的中继器,该中继器具有三个数据绑定容器的布局,语法如下

<%= DataBinder.Eval(Container.DataItem, "UDate" %>
<%= DataBinder.Eval(Container.DataItem, "User" %>
<%= DataBinder.Eval(Container.DataItem, "Update" %>

我现在被要求改变代码,使它使用LinqToSql

我有以下将选择从S_Updates

Dim CaseUpdate = From u in dc.S_Updates
                 Where u.S_Ref = m_CaseRef
                 Order By u.S_Date
                 Select u

我如何改变这个,使我得到…

CaseUpdate.UDate instead of CaseUpdate.S_Date, 
CaseUpdate.User instead of CaseUpdate.S_User and
CaseUpdate.Update instead of CaseUpdate.S_Update

算出来了....

Dim CaseUpdate = From u in dc.S_Updates
                 Where u.S_Ref = m_CaseRef
                 Order By u.S_Date
                 Select New With {.UDate = u.S_Date,
                                  .User = u.S_User,
                                  .Update = u.S_Update}

最新更新