Question

I store encrypted email addresses in my Database and use the DoDecrypt Function of mine, to display the unencrypted email addresses in a AspGrid

So my LINQ query is something like

Dim Query = From c In DB.Something Select New With {.Email = DoDecrypt(c.Email)}

Which returns a set of the emails in debug mode...

After using a Linq to datatable function the results returned are the ones found in the Database, which are the encrypted ones.

What is going wrong here? How should i modify my Linq query?

And here is the Linq to datatable function

 Public Shared Function ToDataTable(DB As System.Data.Linq.DataContext, query As Object) As DataTable
        If query Is Nothing Then
            Throw New ArgumentNullException("query")
        End If

        Dim cmd As IDbCommand = DB.GetCommand(TryCast(query, IQueryable))
        Dim adapter As New SqlDataAdapter()
        adapter.SelectCommand = DirectCast(cmd, SqlCommand)
        Dim dt As New DataTable("sd")

        Try
            cmd.Connection.Open()
            adapter.FillSchema(dt, SchemaType.Source)
            adapter.Fill(dt)
        Finally
            cmd.Connection.Close()
        End Try
        Return dt
    End Function
Was it helpful?

Solution

You need to actually resolve the query, it is late bound by default, but if you're actually wanting to resolve the query, you need to just call .ToList(). I've just wrapped your query in brackets below and called .ToList() at the end. Not sure if this is the exact VB syntax (going from C# knowledge here), but the principal is still the same.

Dim Query = (From c In DB.Something Select New With {.Email = DoDecrypt(c.Email)})
.ToList()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top