LINQ Filtering List Objects?
Mar 1, 2011
I have list object and I need to check id in a comma separated string using LINQ in VB.NET, something like this:
dim strId as String = "1,2,3,5,"
dim myList = from objmylist where objmylist.id in (strId)
View 4 Replies
ADVERTISEMENT
Apr 13, 2011
I am using LINQ - VB.Net I want to filter my List object by passing String object in the where.
Dim _permittedTransactionCodes As List(Of String) = Nothing 'String object
it is populated with data.
Dim tap100transCodeInfos As List(Of Tap100transCodeInfo) = _dal.GetActiveTap100transCodeByHdrScreenCde(UCase(screenId), "TRAN_CDE")
i am trying something below, but not getting the filtered results
tap100transCodeInfos.Where(Function(x) _permittedTransactionCodes.Contains(x.TranCde))
View 1 Replies
Dec 22, 2010
I have 2 classes
Public Class Shipper
Public Property ShipperID As Long
Public Property CreateDate As DateTime
[Code].....
View 1 Replies
Nov 23, 2011
I'm trying to create a list of days(integer) from a list of dates(date).
I tryed to do this....
[Code]...
View 4 Replies
Oct 11, 2011
I have a list of objects, each with 2 relevant properties: "ID" and "Name". Lets call the list "lstOutcomes".I need to check the list for duplicates (meaning object1.ID = object2.ID, etc.) and set a flag (valid = false, or something) if there is at least one duplicate. Also, it would be nice to send a message to the user mentioning the "Name" of the object, when it fails.I am sure I will need to use the Group By operator to do this, but I am not used to doing that in LINQ, and the examples out there are just not helping me. This article seems to be close to what i need, but not quite and it's in C#.
Here is a starting stab at it...
Dim duplist = _
(From o As objectType In lstOutcomes _
[code]......
help?
View 4 Replies
May 3, 2012
I have a query that 'selects' object of a type:
Dim l as IList(Of Foo) = (From dataRow As DataRow In table.Select()
Where CStr(dataRow("Column1")) = "A"
Select New Foo(CStr(dataRow("Column1")), _
CStr(dataRow("Column2")))).ToList()
What's happening is that if i set a break-point to the constructor of Foo and step, the constructor is hit and the parameters are loaded with the arguments. However, l has empty Foo objects (the members in every object are Nothing). What could be happening here?
View 1 Replies
Jul 7, 2011
I have
Dim objectsList as List(Of Object) = GetAllObjects()
' Filter from Objects just Persons '
Dim peopleList as List(Of Person) = ???
What is the most efficient and effective LINQ expression to do it?
EDIT
1 Dim selectedObjects As List(Of Object) = GetAllObjects()
2 Dim selectedPeople As IEnumerable(Of Person)= selectedObjects.OfType(Of Person)
3 Dim people As List(Of Person) = selectedPeople.ToList()
Error on 3:
Value of type
'System.Collections.Generic.List(Of
System.Collections.Generic.IEnumerable(Of Person))' cannot be
converted to
'System.Collections.Generic.List(Of Person)'.
View 3 Replies
Apr 27, 2012
I figure I should use 'Aggregate' but apparently I am getting it wrong First I get a list of my Entity objects Dim employers As List(Of myEntity) = (New XXXX()).getZZZ(userName, userType) Then I figured this would be a way to put all the names in a string Dim names as String = employers.Aggregate(Function(current, [next]) current.Name & " " & [next].Name)
[Code]....
View 2 Replies
Feb 3, 2010
Basically, I am trying to write a LINQ to Objects statement where the relationship is a grandparent, parent, child relationship. (You could also call it a Master Detail relationship.)
In Legacy code here is a simplified version what I am trying to accomplish.
Dim coverages As New List(Of Coverage)
Dim coverage As Coverage
For Each rl In oClaimsPolicy.RiskLocations
coverage = New Coverage
coverage.Level = "Location"
[Code] .....
If is it not clear one Location can have many Items and one Item can have many Coverages. I basically want to list the items and show the relationship between grandparent (Location), parent (Item) and child (Coverage).
View 5 Replies
Jul 3, 2011
I am having so trouble with the ToUpper() procedure with strings. I am using LINQ to find unique values in a list of objects. In that whole process I set the values to compare to all lowercase in order to get a proper list. My goal is to populate a dropdown list with the values. I'm attempting to set the first letter of of the string to uppercase and keep the rest lowercase however the toUpper() procedure is not working?
Private Function FixCase(ByVal strIn) As String
Dim strOutput As String
Dim intStringLength As Integer = strIn.Length - 1
strOutput = strIn.Substring(0, 1)
[code].....
View 5 Replies
Aug 31, 2011
I don't know if this is doable, maybe with Linq, but I have a List(Of MyType):
Public Class MyType
Property key As Char
Property description As String
End Class
And I want to create a Dictionary(Of Char, MyType) using the key field as the dictionary keys and the values in the List as the dictionary values, with something like:
New Dictionary(Of Char, MyType)(??)
Even if this is doable, internally it will loop through all the List items, I guess?
View 3 Replies
Mar 8, 2010
Why does the following query raise the error below for a row with a NULL value for barrel when I explicitly filter out those rows in the Where clause?
Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _
Where Not IsDBNull(row.Cal) AndAlso tiCal_drop.Text = row.Cal _
AndAlso Not IsDBNull(row.Tran) AndAlso tiTrans_drop.Text = row.Tran _
[code]....
Run-time exception thrown : System.Data.StrongTypingException - The value for column 'barrel' in table 'conformal' is DBNull.
How should my query / condition be rewritten to work as I intended?
View 2 Replies
Jun 7, 2012
On my view there is a datatable holding a collection of ServerRow and 4 textboxes (Hostname, OS, Location, Zone). When the user types into any of the 4 boxes I want to immediately filter this list. I have this code setup and ready to go that on the set method of each textbox property I call the filter method.
Now onto the problem: if I have 4 criteria that means I have 2 to the power of 4 different scenarios. What I would like to do is write a linq statement with all of these scenarios dealt with such that if any of the properties are NullOrEmpty they will not be used in the Where clause and on the flip side if there is a value the corresponding field will be searched with a Contains.
Example
AvailableCis = New ObservableCollection(Of ServerRow)
(_CiData.Where(Function(ci) ci.OS.ToUpper
.Equals(_selectedOS.ToUpper) AndAlso
ci.HostName.ToUpper.Contains(_ciNameFilterText.ToUpper))
.OrderBy(Function(a) a.CiName))
This example shows how it works with 2 criteria and both of those criteria are set.
View 1 Replies
Apr 24, 2009
I am binding a Winforms Grid to an entity. (For reasons I won't go into here it must be bound to the entity, not the result a query) The code is as follows:
grid.DataSource = myEntities.entityName.Where("it.field = " & field)
It works, but it obviously isn't strongly typed. Is there a way to define the Where clause of an entity using a strongly typed notation?
View 1 Replies
Jun 6, 2011
i'm currently working on my thesis e-voting system. and i need to modify my search candidate and search voter form. the data from my database is already loaded in my listview when the system. what i want to do is while i am typing in the search text box, at the same time the items in my list view is being filtered without clicking the search button.
[Code]...
View 4 Replies
Apr 28, 2010
When typing in Visual Studio the list of possible values returned by the Intellisense is not limited to the possible values for the type and instead lists all the items.In the example below after I type the '=' to set the default value for a property, intellisense will list hundreds of possible values instead of just the ProductTypes.Item1, ProductTypes.Item2 & ProductTypes.Item3.
View 1 Replies
Nov 21, 2007
I just converted my project from VS 2005 to 2008 and started getting really bad lag only when intellisense iterates my dataset objects. The cpu maxes out one of my cores for about 2-3 seconds each time the intellisense list pops up. Is this a new feature of the 2008 ide?
View 19 Replies
Jun 2, 2011
I would like to create list of child objects from list of parent object. Like If i have list of bookingroom which has one member room then i would like to create list of room from it.
eg. code:
Dim BookingRoomList As List(Of BookingRoom) = New List(Of BookingRoom)
Dim RoomList As List(Of Room) = New List(Of Room)
BookingRoomList = BookingRooms.FillGrid()
[Code]....
Is there any short cut method instead of iterating over for earch?
View 1 Replies
Jul 20, 2011
I'm having a bit of a 'brain doner' moment here
I have a list of Objects. Each of these Objects contains a list of other Objects (pseudo code) :-
Private Structure Object1
dim Name as string
dim ListOfObject2 as List(Of Object2)
[Code]....
I need to sort the list of Object1 by the Value in Object2. I have a comparison class which sorts Object2 by its Value nicely.
View 13 Replies
Feb 21, 2009
In which situations I should use LINQ to Objects?
Obviously I can do everything without LINQ. So in which operations LINQ to code shorter and/or more readable?
View 7 Replies
Jun 5, 2012
I have a linq query like that:
Elementos = From b In Elementos Where b.Value.IdGrupo = 0 Select b
"Elementos" is a dictionary(of long, MyObject). MyObject has approximately 50 properties.
The problem I have is that I have a new requirement to accept string parameter with a "where" condition. Something like "property1>10 and property2 like 'anystring' or property3<=25". (That means any property could have a condition. I have string and numeric properties.)
I'd like to keep using linq, adding the condition as it comes. I'm aware that it could produce an exception if the condition is misspelled or something, but that's acceptable (by try catchs). I wouldn't want to parse the string to build parameters or anything.
View 2 Replies
Nov 20, 2009
I am creating a tool that interfaces with an API for a CD/DVD burner. I have created several custom classes that will hold the information for the disk sets (which consist of a data path and a label file among other information. The DiskSet class has a list of Include objects. My proposed XML output would be something similar to the following:
<DiskSets>
<DiskSet>
<Name>MySet 1</Name>
[code].....
I am attempting to traverse the Includes collection (I have tried List and Binding List as I am also using this in a pair of datagridview controls) and it keeps returning Expression of type 'Object is not queryable. Make sure you are not missing an assembly reference and/or namespace import for the LINQ provider." How can I use LINQ to pull a list of the Include objects under each DiskSet object for transformation into XML? I am hoping to keep this restricted to this one block of code if possible.
View 7 Replies
Apr 14, 2010
Using the following code:
Private Sub MakeMeSomeXmlBeforeRyanGetsAngry()
Dim db As New MyDBDataContext
Dim customer = From c In db.Customers Select c
[code]....
I am attempting to serialize my linq collection of customers. But it keeps throwing
Type 'System.Data.Linq.DataQuery`1[MyDB.Customer]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. See the Microsoft .NET Framework documentation for other supported types. My issue is that I have already marked the dbml Serialization Mode to UniDirectional and when I check the dbml codebehind all of the DataContract()> and DataMember()> elements are there. I have tried adding various dataloadoptions and setting deferredloading to false, but no luck.
View 2 Replies
Dec 15, 2011
How to Join the objects in a LINQ select in this sample (C# variants accepted as well):
Class Room
Public Area As Integer
End Class
Class RoomPair
[code]....
View 4 Replies
Mar 10, 2010
Im trying to use LINQ to query Objets. I'm doing the following:
Dim myList As Generic.List(Of MyItem) = (From ThisItem In LinqToSqlObject.Items _
Join Folder In LinqToSqlObject.Folders _
On Folder.Id Equals Item.Id _
[Code]....
This however will not return any item that has a ParentItemId of null. I am trying to do a left join so as to return all "Item" regardless of whether it has a parent or not. I am aware that this is feasible in C# by adding an "into X" on the join, and selecting from X.DefaultIfEmpty(), this however does not appear to work in VB.Net.
View 2 Replies
Dec 10, 2010
I have the following XML file
<Test>
<Modules>
<Module Name= "Test1">
<QueueName Name="Test1Active1" Active="True"></QueueName>
<QueueName Name="Test1Active2" Active="True"></QueueName>
[Code]...
View 1 Replies
Oct 2, 2010
I'm trying to figure out how to add an enumeration to an object with Linq. For example:
Dim thingBlock = <Things>
<Thing Name="Ish">
<SmallThing>Jibber</SmallThing>
[code].....
View 1 Replies
Jan 24, 2010
I need two seperate lists, which every item is Integer, String, Bitmap - and one which every item is Integer, String String. However I don't know how to do this, or even where to look - I've googled for custom objects and custom object lists. What I'm trying to do is this.Custom Object1 is Integer, String, Bitmap Custom Object2 is Integer, String, String
In one thread I'll be adding items to List1(Of Object1), and processing them, and adding the results to List2(Of Object2), however I need to be able from other threads to look at the list and say only give me the items where Integer = (my thread ID), is this possible? Any help, or even links to information that would be relevant to this request would be helpful?
View 2 Replies
May 26, 2012
y have this class
Private Class MyClass
Public Property propertyOne() as String
Public Property propertyTwo() as String
[code].....
View 2 Replies
Apr 5, 2011
I'm trying to create a list of all my objects from several lists of objects using Union.
Return Chart.AnnotativeNodes.Union( _
Chart.DecisionNodes.Union( _
Chart.EndNodes.Union( _
Chart.StartNodes.Union(Chart.WorkCenterNodes))))
The above line gets an error because I can't union List(of AnnotativeNode) with List(of DecisionNode). Each list defined like List(of EndNode) or List(of StartNode), but each class inherits from the base type Node.Is there a possible way to union these to get a result of IEnumerable(of Node)?
View 1 Replies