Vb.net 在LINQ EF查询中重置值
有没有办法在LINQ查询中重置网格显示的值 例如,下面的查询使用两个返回值设置fullname,如果可能,Id希望在查询中执行的操作是,如果IsAccountVerified(字节列0或1值)值为1,则将其转换为true;如果为false,则将其转换为false。如果为其他值,则将其转换为false,以便返回值包含IsVerified的字符串值,而不是其数据库整数值Vb.net 在LINQ EF查询中重置值,vb.net,linq,entity-framework,Vb.net,Linq,Entity Framework,有没有办法在LINQ查询中重置网格显示的值 例如,下面的查询使用两个返回值设置fullname,如果可能,Id希望在查询中执行的操作是,如果IsAccountVerified(字节列0或1值)值为1,则将其转换为true;如果为false,则将其转换为false。如果为其他值,则将其转换为false,以便返回值包含IsVerified的字符串值,而不是其数据库整数值 Using ctx As New IdentityEntities() Dim users = (From d
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
但是如果可能的话,我更愿意在查询中这样做问题还不清楚。如果我理解d.IsAccountVerified是
字符串
。这可能是个骗局吗
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()
而不是在RowCreating事件中将“1”从IsAccountVerified转换为“True”。如果d.IsAccountVerfied=1IsAccountVerified是一个字节列0或1值,我想让查询返回“True”,例如Let verified=“True”。您想将True作为字符串还是布尔值?作为字符串用于gridview显示要在
gridview
中使用,可以在绑定中使用布尔值。无论如何,我已经更新了答案。