|
-
May 12th, 2009, 03:05 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Linq Query Question
Hey, guys. So I'm still learning LINQ here, and am having an issue with what should be an easy query.
Basically, my query is this: I want all of the characters that are of a membership level in a given area that is of admin or above.
This is what I have so far:
Code:
Dim L As List(Of Character) = (From C In MasterCharacterList.Characters.Values _
Where Me.Item(C.CharID).DreamLevel.ContainsValue( _
(From L In _Levels Where L.Value.Admin Or L.Value.BotMaster Select L.Value.MemberLevel).ToList.ForEach) Select C)
Me, in this case, is the members collection.
So far, I can't get the query to turn into a list (hence no .tolist at the end.) I know there's something wrong here, but I'm not sure what.
Last edited by Campion; May 12th, 2009 at 03:22 AM.
-
May 12th, 2009, 05:39 AM
#2
Re: Linq Query Question
Well, my first advice is to format your code so you can see what's going on. It's very hard to read that code.
vb.net Code:
Dim L As List(Of Character) = (From C In MasterCharacterList.Characters.Values _
Where Me.Item(C.CharID).DreamLevel.ContainsValue((From L In _Levels _
Where L.Value.Admin Or L.Value.BotMaster _
Select L.Value.MemberLevel).ToList.ForEach) _
Select C)
Ahhhhh. Isn't that better? Now you can actually see the intent.
As for the question, I think we will need more information about the types involved. What are the relationships? What's a DreamLevel? Etc,. etc.
-
May 12th, 2009, 08:17 AM
#3
Re: Linq Query Question
I'm suspecting the problem is here:
Code:
(From L In _Levels _
Where L.Value.Admin Or L.Value.BotMaster _
Select L.Value.MemberLevel).ToList.ForEach)
But don't know for sure. Do they work independently? Can you do something like:
Code:
Dim myL As List(Of Levels) = (From L In _Levels _
Where L.Value.Admin Or L.Value.BotMaster _
Select L.Value.MemberLevel).ToList
Dim L As List(Of Character) = (From C In MasterCharacterList.Characters.Values _
Where Me.Item(C.CharID).DreamLevel.ContainsValue(myL.ForEach) _
Select C)
Does myL produce a proper list?
-
May 12th, 2009, 02:24 PM
#4
Thread Starter
Frenzied Member
Re: Linq Query Question
Sorry, JL. The indentions don't always copy over correctly. 
Dreamlevel is a collection that contains a member's membership level in a certain area (dream.) The number this is the key to the memberlevel for what he can and cannot do.
Jenner, I won't be able to test out what you've suggested until tomorrow. Work is until O'dark 30 tonight. But I will try it.
-
May 13th, 2009, 01:39 PM
#5
Thread Starter
Frenzied Member
Re: Linq Query Question
Well, I compromised a little bit and did half LINQ, and half FOR EACH, but it still achieves the same result. However, I'd still like to figure out how to do it all in LINQ eventually.
Code:
Private Function GetAdmin() As List(Of Character)
'return variable
Dim Li As New List(Of Character)
'Grab the list of memberlevels that hold admin rank or above
Dim Le As List(Of Integer) = (From L In _Levels Where L.Value.Admin Or _
L.Value.BotMaster Select L.Value.MemberLevel).ToList
'Here, we compare the list of admin levels with what a member actually has. If he has an
'admin level or above in any dream in the continuity, he will be included on the list,
' regardless of whether or not he may be able to access that dream to begin with.
For Each M As Member In MasterCharacterList.Members
For i As Integer = 0 To Le.Count - 1
If M.DreamLevel.ContainsValue(Le.Item(i)) Then
Dim C As Character = MasterCharacterList.Characters.Item(M.ID)
If Not Li.Contains(C) Then
Li.Add(C)
End If
End If
Next
Next
Return Li
End Function
I'll set this for resolved, but any input would be greatly appreciated.
-
May 13th, 2009, 02:49 PM
#6
Re: [RESOLVED] Linq Query Question
I think I got what you're looking for, you're trying to compare one list vs. another list and if ANY items from list 2 are found in list one, then flag that character?
How about using "Intersect" to get the items that appear on both lists:
Code:
Dim Le As List(Of Integer) = (From L In _Levels _
Where L.Value.Admin Or L.Value.BotMaster _
Select L.Value.MemberLevel).ToList
Dim Lc As List(Of Character) = (From C As Character In MasterCharacterList.Characters.Values _
Where Me.item(C.CharID).DreamLevel.Intersect(Le) _
Select C).ToList
-
May 13th, 2009, 03:21 PM
#7
Thread Starter
Frenzied Member
Re: [RESOLVED] Linq Query Question
Intersect is expecting a KVP(of string, integer), but I'm not sure how to get that when the key for_Levels in an integer.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|