Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
VB.net - Macro Substitution
Message
De
15/11/2010 03:59:17
 
 
À
14/11/2010 14:51:38
Information générale
Forum:
ASP.NET
Catégorie:
LINQ
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01488984
Message ID:
01489099
Vues:
72
>Trying to translate your example into my code, i came up with the following - still getting the error "Method 'Boolean OptionCheck_WithArray(Int32)' has no supported translation to SQL."
>Dim result_Match =
>            (From Row In result_0
>            Where OptionCheck_WithArray(Row.SecurityCode)
>            Select Row).ToList()
>
>Public Function OptionCheck_WithArray(ByVal n_Value2 As Integer) As Boolean
>        ' TODO: need to loop through array
>        Return If((n_Value2 And SecurityCodes(0)) = SecurityCodes(0), True, False)
>End Function
>The result_0 list/collection is the result of my earlier select and has records. It also has a value of 102 (in this example) in the SecurityCode field for all the records.
>
>The SecurityCodes(0), used in the function, has a value of 4. This is collected earlier in the program from the Active Directory for that specific user. So the function should return a true in this case - not that this really matters right now, because LINQ does not like me calling that function.

Looks like you are still working with List(Of Integer) so this should work:
Dim results As New List(Of DummyRow)()
        results.Add(New DummyRow(New List(Of Integer)() From {1, 4}))
        results.Add(New DummyRow(New List(Of Integer)() From {4, 8}))
        results.Add(New DummyRow(New List(Of Integer)() From {4, 16}))

        Dim UserCodes As New List(Of Integer) From {1, 8}

        Dim MR As List(Of DummyRow) = (From x In results Where OptionCheck_WithArray(x.Codes, UserCodes) Select x).ToList()
with
Public Function OptionCheck_WithArray(ByVal userCodes As List(Of Integer), ByVal test As List(Of Integer)) As Boolean
        For Each i As Integer In test
            If userCodes.Contains(i) Then
                Return True
            End If
        Next
        Return False
    End Function
But *please*, since this is essentially a bitwise comparison, consider using Enums instead. Why use an array of integers when one would do. If you need more options use a Long instead of an Integer. Of course if you *do* need more than 64 then you will have to stick with a List...
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform