LINQ Where Statement In Collection?

Mar 28, 2012

I have a Customer object which has a collection of ContactNumbers. Is it possible with LINQ to get a list of Customers where one of the contact numbers = '123'?

Public Class Customer
Public Overridable Property ContactNumbers As List(Of ContactNumber)
End Class

[Code].....

View 1 Replies


ADVERTISEMENT

.net - Search The Collection Of A Collection In LINQ Where Clause?

Apr 15, 2009

I've got the following ADO.NET Entity Framework Entity Data Model:I want to find all the Policyholders with both a Service of a given Id and also a Keyword of a given Status.

This LINQ Does Not Work:

Dim ServicesId As Integer = ...
Dim KeywordStatus As Integer = ...
Dim FoundPolicyholders = From p As Policyholder In db.PolicyholderSet.Include("Keywords").Include("Services") _
Where p.Services.Id = ServicesId _
And p.Keywords.Status = KeywordStatus _
Select p

The Where clause cannot search the p.Services and p.Keywords EntityCollections in that way.

[Code]...

View 1 Replies

Search The Collection Of A Collection In LINQ Where Clause?

Apr 15, 2011

search the collection of a collection in my LINQ Where clause?

View 11 Replies

.NET LINQ - Count Of Collection Within Collection?

Apr 14, 2011

Take the following scenario:

Public Class Store
Public Overridable Property Areas As List(Of Area)
End Class
Public Class Area

[code]....

What's the quickest way to get a total count of shelves for a store? I.e. for a store I get the total count of areas by using Areas.Count Or will I need to loop through each area and tally the count of shelves?

View 2 Replies

Sql - Perform An Inline Select Statement In A LINQ Statement?

Jun 24, 2011

I have the following SQL:

[Code]...

I want to put it (the select count statement) in this LINQ statement so I can get the sales count in my linq statement: Dim TheLeads = (From L In DB.Leads Where L.IsDeleted = False Select L).ToList() Is this possible to do in LINQ?

View 1 Replies

LINQ To XML, Only Can Get First Item In Collection?

Sep 8, 2010

Here is an example of my xml doc:

<?xml version="1.0" encoding="utf-8"?>
<employeedata>
<employee>
<firstname>Bob</firstname>
<lastname>Anderson</lastname>

[Code]...

However, only the first phone number (Office) displays in the listbox. The phoneinfo collection has both <phone> elements, but the For Each statement doesn't seem to iterate thru.

View 8 Replies

Build A String From A Collection With Linq?

Oct 8, 2009

I'm building flat file content from collections of strings.

Example collection: A, B, C, D, E, etc.

I want to be able to output these values to a string with line feeds in one swoop with Linq if possible.[cod]e...

View 8 Replies

Get Last Instance Of Collection Controls Using Linq?

Mar 6, 2012

How to get the last instance of label control in List (of Control) using linq?

View 4 Replies

Linq Iterate A Control Collection?

Jun 29, 2009

Private Function GetWebDataGridOKButtonId() As String
Dim ctls As ControlCollection = _
WebDataGrid1.Controls(0).Controls(0).Controls

[Code]....

This is not working for me. I am trying to iterate a control collection and return one control ID.

View 2 Replies

Filtering A Collection With Linq And Multiple Criteria?

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

Is There A Native LINQ Way To Return A Typed Collection

Apr 18, 2011

Is this the most straight forward way to return a typed collection?Here's the key line of code which returns a implicit type of IEnumerable that used to manually loop through to manually recreated a TYPED collection. Is there any native LINQ way to return a typed sorted collection without this recreating of the collection? [code]

View 2 Replies

LINQ - Select A *TYPED* Item In A Collection?

Mar 1, 2011

Can I use LINQ to return an item in a collection that is the same TYPE as the items in the collection? I am a LINQ Noob trying to avoid looping.

Dim mostRecentlyCreatedQuestionnaire As ParentQuestionnaireItem =
CType((From P In questionnaireCollection Order By P.Metadata.CreateDate Descending).Take(1), ParentQuestionnaireItem)

I get an "unable to CAST" error when I include the CTYPE function. I kind of expected that error, but I imagine that if I coul dnot do this, LINQ's usefulness would be diminished and therefore assume that there must be a way..

View 2 Replies

Return Type For Collection From LINQ Query?

Oct 15, 2010

I have a method, that returns a group of accounts

Public Shared Function GetAllNotesByUser(ByVal UserID As Guid) As Account (??)
Using db As New MyEntity
Dim query= (From A In db.Account _

[Code].....

I would then like to pass this to another function to calculate the totals for all the accounts in the collection. Is it best practice to return an Ienumerable, a generic list, I'm just not sure what works best with LINQ and the entity framework.

View 4 Replies

Use LINQ To Query The Items Collection Of A ComboBox?

Jul 14, 2011

Is it possible to use LINQ to query the items collection of a ComboBox & get the index of the item that matches what I'm looking for?

View 4 Replies

XML Feed - How To Get Collection Of Elements (Assets) Via LINQ

Mar 9, 2011

I have the following XML which I load via XDocument.Load(uri) or XElement.Load(uri). I am having trouble getting a collection of <asset> elements via LINQ.

Here is a snippet of the XML I'm trying to query:
<assetCollection xmlns="tag:aisle7.net,2009:/api/1.0">
<title>All Assets</title>
<description>Collection containing all assets in the system</description>
<resourcePath>/us/assets/~all</resourcePath>
[Code] .....

View 2 Replies

C# - Use Linq To Do A WHERE Against A Collection Object (using Netflix Data Source)?

Sep 18, 2010

I am using LinqPad to learn Linq by querying the NetFlix OData source.Here is the query I got working which is awesome.[code].....

(Pardon all the comments...it is a testament to the fact I am experimenting and that I will change the query for various needs).There are two thing I cannot figure out.First.Let's say I only want to return the first 10 results.Second (and most importantly). I want to filter by a partial string of the genre.Each title contains a Genres collection. I want to show only Genres where the Name contains a certain string (like "Family").Even better filter using Titles where genre.name.contains "firstFilter" AND "secondFilter".Basically, I want to filter by genre(s) and I cannot figure out how to do it since Title contains its own Genres collection and I cannot figure out how to return only title that are in one or more genres of the collection.

View 3 Replies

Calculate Sumproduct By Applying LINQ To List Collection?

Feb 24, 2012

Can I calculate sumproduct by applying LINQ to List collection?[code]...

How to return the weighted Percentage for each category with LINQ? Weight is the Value.

View 5 Replies

Linq - Select Single Item From Child Collection?

Jan 12, 2012

I have a parent child collection objects and was wondering how to get a single item from the child collection using Linq

[Code]...

View 2 Replies

Linq Query To Compare If Collection Contains List Of String?

Feb 3, 2012

I am using a path comparison to find any children tags which works well when there is only 1 tag selected. This is my code for when multiples tags are selected but it is not working. Can you point me in the right direction?

Single Tag Selection (working)
Dim tagpath = uxTags.SelectedItem.Text
lnqCases = From i In lnqCases Where i.HelpDeskTagItems.Any(Function(x)

[code]...

View 1 Replies

Use Linq To Entities To Group A Collection Without Using Anonymous Types?

Apr 24, 2012

The documentation has an example about grouping on multiple properties[code]...

Is it possible to rewrite the original query to just return IEnumerable(Of CustomerRegionGroup), or do I have to use the anonymous type, and run a second query on the result of the first?

View 1 Replies

Cannot Iterate Of A Collection Of Anonymous Types Created From A LINQ Query?

Mar 17, 2010

Every LINQ example I have seen for VB.NET anonymous types claims I can do something like this:

[code]...

Now when I go to iterate through the collection(see example below), I get an error that says "Name "x" is not declared. For Each x in Infos It's like VB.NET doesn't understand that Infos is a collection of anonymous types created by LINQ and wants me to declare "x" as some type. (Wouldn't this defeat the purpose of an anonymous type?) I have added the references to System.Data.Linq and System.Data.DataSetExtensions to my project. Here is what I am importing with the class:

[code]...

View 4 Replies

Order A Collection Based On A Child Property Using LINQ Or A Lambda?

Jan 26, 2012

I get the following string expression provided:"ChildObject.FullName" ...where ChildObject is an instance property on the MyObject1 type.ChildObject has a property named "FullName" and I want to sort a collection of type "MyObject1" based on this child properties "FullName" value.

I can do this all day long on properties directly on MyObject1 but I run into 2 challanges when doing it on a child instance and I can't get all the pieces working. The main 2 challanges are:

MyObject1 has a few different child property types so I can't hardcode the type for ChildObject. The string could be of any type.The sort expression is a String and not a known type.Above the value returned from the last line in the expression (if I run the code outsode the OrderBy method, does provide me the 'FullName' information I need. So the code must be close, but it still does not work.

Any ideas on how I can accomplish this? What I am trying to prevent is hardcoding a series of 'If' blocks on the child's type to then hardcode in its type to the sort or OrderBy method.

View 2 Replies

Working With System.collection.generic.Ienumerable/XML Linq Queries?

Oct 22, 2009

This is really a continuation from my earlier post. I've never worked with this datatype/collection (system.collection.generic.Ienumerable) before so I'm struggling to declare the query globally so I can reference the results within other sub routines/functions. I also am struggling to convert it to other types.how I can convert the collection of xml elements/system.collection.generic.Ienumerable into an xmltextreader (I know I will have to change the query below as it select the value of the node and not the node itself) I imagine by converting the query result to system.IO.stream My first port of call was MSDN but I find the material very difficult to understand for this particular subject.

[Code]...

View 3 Replies

.net - Linq Query If Statement?

Jun 24, 2011

Ok im trying to do a if statement in Linq and was wondering if it was possible to do something like:

Dim loadFriends = From p In db.UserRelationships Where p.aspnet_User.UserName = User.Identity.Name _
Or p.aspnet_User1.UserName = User.Identity.Name And p.Type = 1 _
Select New With {if p.aspnet_user1.user = "a certan username" then .username = _
p.aspnet_user.username else .username = p.aspnet_user1.Username}

[Code]...

View 1 Replies

.net - XML Literal With Linq Statement?

Oct 7, 2009

I am going to be performing an XSLT transformation, transforming XML to an HTML table. It's tabular data, so that's why I'm not using div's.

[Code]...

View 3 Replies

Is There A Better Way To Do LINQ Statement Block

Aug 13, 2009

I'm relatively new with LINQ, but I'm going to be getting into it a lot more. Is the following a practical application of LINQ, or is there a better way to do something like this? [code] I was thinking if I could get the property name somehow as an object I could just do one LINQ statement,

View 5 Replies

Convert The Following VB Code To A LINQ Statement?

Oct 8, 2009

I only want to return a certain number of rows into the DataTable via LINQ's Take or use it on the Rows property, but I am not sure how or where to do it: Here is the current code:

Dim dt As DataTable = GetDataTable("sp", params)
For Each dr As DataRow In dt.Rows
Dim o As New OR()

[code].....

View 1 Replies

Getting Result Of Linq Statement Out Of A Function?

Jun 16, 2011

I have something that I want to do and what looks very simple, but I cannot get it to work. I want to build a function that gets as input a xdocument and some other strings. It should have a return that contains a filtered part of the xdocument in a way that I can use it as input for a new Linq function. This is what I mean:

Private Function fncGetFilteredDecendantsOfNode(ByVal xdocDoc As XDocument, _

[Code]...

View 2 Replies

How To Turn Query Into A LINQ Statement

Sep 30, 2009

How can I turn the following query into a LINQ statement? [code]

View 1 Replies

LINQ Statement Not Updating Database?

Jul 15, 2010

I have the following code:[code]When I run it, looking at the debugger everything looks okay but when I check the database table it is supposed to be inserting into - the column values (for occupantnum) haven't changed - they are all still null! Not sure if this is related, but note that I've now updated j to explicitly be an integer. I noticed while debugging that wResident.occupantnum was appearing as Type "Integer?" - but this doesn't seem to have made any difference - when I rerun it it still says Type "Integer?"

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved