有没有办法在LINQ查询中重置网格显示的值?
例如,下面的查询使用两个返回值设置fullname,如果可能,Id喜欢在查询中执行的操作是将IsAccountVerified(字节列0或1值)值转换为true(如果为1),如果是其他任何其他值则为false其他任何东西,以便返回携带IsVerified的字符串值而不是其数据库整数值。
Using ctx As New IdentityEntities()
Dim users = (From d In ctx.useraccounts
Join e In ctx.userprofiles On d.Id Equals e.UserAccountId
Let fullname = e.FirstName & " " & e.LastName
Select New With {
d.Id,
fullname,
d.Username,
d.IsAccountVerified
}).ToList()
Return users
End Using
我目前正在转换RowCreated事件中的值
Public Sub gvSiteUsers_RowCreated(sender As Object, e As GridViewRowEventArgs) Handles gvSiteUsers.RowCreated
Dim verifyCol As Integer
For Each col As DataControlField In sender.Columns
If col.HeaderText.ToLower().Trim() = "isverified" Then verifyCol = gvSiteUsers.Columns.IndexOf(col)
Next
For Each row As GridViewRow In sender.Rows
If row.Cells(verifyCol).Text = "1" Then
row.Cells(verifyCol).Text = "True"
Else
row.Cells(verifyCol).Text = "False"
End If
Next
End Sub
但是如果可能的话,我宁愿在查询中这样做
答案 0 :(得分:0)
问题不明确。如果我理解d.IsAccountVerified是string
。可能这可以做到吗?
Dim users = (From d In ctx.useraccounts
Join e In ctx.userprofiles
On d.Id Equals e.UserAccountId
Let fullname = e.FirstName & " " & e.LastName
Let verified = If(d.IsAccountVerified = 1, "True", "False")
Select New With
{
d.Id,
fullname,
d.Username,
verified
}).ToList()