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
ADVERTISEMENT
Jan 7, 2012
And here is the code that produces the error
CODE:
How can i cast this one?
View 1 Replies
Jan 6, 2010
I am writing a message system on my server, the xml is something like this
<xml>
<entry>
<sender>[code]....
my problem now i guess is 2 fold, i wish to combine the first 3 queries into a single query and place in a list or a collection or is there a way to do this with a single query that will give me my desired result?
View 1 Replies
Jun 17, 2011
how to insert records with dapper-dot-net. However, the answers, while informative, didn't seem to point me in the right direction. Here is the situation: moving data from SqlServer to MySql. Reading the records into an IEnumerable<WTUser> is easy, but I am just not getting something on the insert. First, the 'moving records code':
// moving data
Dim session As New Session(DataProvider.MSSql, "server", _
"database")
Dim resources As List(Of WTUser) = session.QueryReader(Of WTUser)("select * from tbl_resource")
[code]....
View 1 Replies
Jul 9, 2012
Ok, letīs see, iīm kind of new to this so letīs see if you can follow...I have a IEnumerable list of objects:
Dim
objStudentUsers
As
[code].....
View 2 Replies
Mar 11, 2010
This is weird. I have a class that inherits from IEnumrable whose Count property is reporting 0 (zero) elements but the For Each loop steps into the loop body and tries to use the variable where it should just be moving on. My code:
On Error Resume Next
Dim d As Foo
For Each d In fooCollection
' use d and throws an exception
Next d
Weirder still, every time d is accessed i get an exception thrown in the output window:
A first chance exception of type 'System.NullReferenceException'
but i'm not stopping on the exception (not in a try/catch block).Is "On Error Resume Next" causing this weirdness?
Weirdness found:Per Rowland's and JohnH's comments i checked the Foo class:The GetEnumerator method inside of Foo didn't actually return anything! It had an empty body. That coupled with the On Error Resume Next before the loop caused the havoc! Wow this was ugly.
View 3 Replies
Jul 6, 2011
IEnumerable interface provides a instance method GetEnumerator that returns IEnumerator type opject .That's okey .But its very hezy to me that how IEnumerable objects are able to work with For Each loop ?When using For Each GetEnumerator method is not called directly from my code .Then from where and how GetEnumerator is called ?Basically my question is that when a class implements IEnumerabel interface then how a distinct behaviour is attached to that class?How it is used with For Each without calling GetEnumerator ?Here is the sample code that i am using :
Public Class Person
Public firstName As String
Public lastName As String
Public Sub New(ByVal firstName As String, ByVal lastName As String)
[code]....
View 3 Replies
Jan 22, 2010
I have the follow Linq query that is in a web application that was converted from .NET 1.1 to 3.5:
dim objListOfFilteredDataRows = from datarows as datarow in objDataSet.tables(0).rows _
where datarows("SomeColumn") = SomeValue
I have the exact same query in an application that was created using .NET 3.5 and the query returns an IEnumerable. However the query in the converted application is returning:
{Name = "WhereEnumerableIterator`1" FullName = "System.Linq.Enumerable+WhereEnumerableIterator`1[[System.Data.DataRow, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"}
**Edit: When I highlight the expression, the intellisense says that it doesn't know the type of objListOfFilteredDataRows and assumes its a type of "Object". Why is the type not infered in the converted 1.1 application but is infered in the "native" 3.5?**
What am I missing here? How do I convert the "WhereEnumeratorIterator`1 to an IEnumerable?
View 5 Replies
May 28, 2010
I've long since built a way around this, but it still keeps bugging me... it doesnt help that my grasp of dynamic LINQ queries is still shakey.
For the example:
Parent has fields (ParentKey, ParentField)
Child has fields (ChildKey, ParentKey, ChildField)
Pet has fields (PetKey, ChildKey, PetField)
[Code].....
The above Join call doesnt work. I sort of understand why it doesnt work, but hopefully it'll show you how I tried to accomplish this task.
After all this was done I would have appended a Select to finish the job.
I tried it with the PredicateBuilder with little success. I might not know how to use it right but it felt like it wasnt gonna handle the joining.
View 1 Replies
Apr 4, 2012
How to give another function's returned value in LINQ Ienumerable.
Private function GetFruitColor(fruit) as string
'It returns fruit color.
'If valid fruit and color not available, it returns ""(empty string)
[code].....
'Below code is wrong. but please suggest me how to correct it. My intention is, I want output collection(say dictionary) of each fruitname and its color(returned by other function call) for all the fruits which the GetFruitColor is not nothing(it can be empty or valid string).
Dim query = _
fruits.Where(Function(fruit) k= GetFruitColor(fruit) if not k is nothing select fruit, k)
End Sub
View 8 Replies
Oct 19, 2010
My particular example is fairly complex but I think the concept would apply equally to something like a logging system so I'll use that instead for ease of explanation. It's a ficticious example, please don't harp on or agonise over what is achitectually, programatically or morally wrong with the example itself
[Code]...
I don't want to 'cheat' and resort to a long-winded way of doing it when performance isn't critical here and I'm moderately confident it can be done in a single LINQ statement.
View 1 Replies
Jun 18, 2009
Is there any particular reason why creating a reference to an object in an IEnumerable Linq query would be really slow? I have a Linq query list consisting of my own objects (count is about 200).I was doing a time-critical task, and this line (which was used a lot in a loop) took nearly a millisecond to execute:
Dim CurObject as MyClass = QueryResult(CurIndex)
View 2 Replies
Jul 7, 2010
I have created a Dictionary class (MyDictionary for the example). I am currently trying to pass MyDictionary into a function, filter it into a new instance of MyDictionary and pass this new instance into another method. When I am attempting to create the second instance from the filtered first instance of MyDictionary via Lambda Expressions and the ToDictionary Method, I am getting the following error:
Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.Int32,System.String]' to type 'MyDictionary'. I have simplified the example and recreated it in LINQPad and am getting the same error.
Here's the simplified version of my code:
[Code]...
View 2 Replies
Mar 15, 2008
I'm binding a DataGridView to a BindingSource to a LINQ IEnumerable, I found that the BindingSource.Find method throws an exception because .Find isn't implemented in IEnumerable (and the BindingSource just passes the call to it's DataSource). I need to use BindingSource.Find to select/highlight a particular row in the DataGridView.
Is there a feasable way to extend my DataContext to support this behavior w/o breaking anything else? I expected to find the code out there already, but I've searched exaustively with no luck.Without it, I cannot "move" the BindingSource using .Position and that's a pretty common use of the BindingSource I think.
View 1 Replies
Oct 21, 2009
How can I convert an object of type System.Data.Linq.DataQuery to System.Linq.IQueryable?I'm working with Visual Basic/Silverlight, and the source code of my query is as follows:
Public Function Get_Cli_Pag() As IQueryable(Of V_Cliente_Pagare)
Dim Qry = From P In Me.Context.Pagares Join C In Me.Context.Codigos On C.Codigo
[code]....
View 1 Replies
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
Apr 15, 2011
search the collection of a collection in my LINQ Where clause?
View 11 Replies
Aug 24, 2011
I have a basic grid of Linq2Sql entities (frmList). I have a separate form for editing (frmEdit). frmEdit has its own DataContext (as that appears to be the recommended way). How can I tell when my detail form has saved changes?
I don't see a built-in method. I am considering raising an event on the detail form when I save the datacontex, but not sure how I consume this event on frmList, and I have a feeling these events are already created for me somewhere?
View 1 Replies
Oct 11, 2010
Let's say I have 3 tables: carts, baskets and eggs where a basket can contain many eggs and where carts contain many baskets. Each basket has a foreign key that maps to a cart and each egg has a foreign key that maps to a basket.I need to return a table that contains these 3 columns:Cart Name | Count of Baskets in Cart | Count of Eggs in Cart.Each table is an EF and I'm using linq with VB.So far, I have 2 queries: one that returns the columns Cart Name and Count of Basket and another one that returns Cart Name and Count of Eggs. How can I combine these two result tables so that I get the results in one table?
Dim query1 = (From cart In myEntities.Carts
Where cart.UserID = TheUserID
Join baskets In myEntities.Baskets On baskets.CartID Equals cart.CartID
[code]...
View 2 Replies
May 9, 2011
I have an object called Result<T> that has a constructor which accepts an argument of IEnumerable<T>. I'd like to be able to pass in a datatable if possible.
I tried datatable.AsEnumerable(), but where I bind to the data it was complaining that 'MyProperty' is not a field or property on type 'DataRow' - which makes sense since 'MyProperty' isn't a property on 'DataRow', but it was a column in my datatable.Is there a way to convert a datatable to something that I can pass into the Result object and still have it bind to, say, a gridview?
View 3 Replies
Mar 13, 2012
I have a function used to filter a list of options to return only those that are lot traced, and, when applicable, also only show items matching a specified pattern:
Private Shared Function FilterResultsLot(ByVal source As IQueryable(Of Item), _
ByVal itemCode As String) As IQueryable(Of Item)
If HasFilter(itemCode, True) Then
[Code].....
View 1 Replies
Mar 17, 2009
I have 2 tables that are related. Each app can relate to many apps. ie, office can be related to word, excel.[code]I would like to do the following query. I use vb.net but c# is ok.Query is to return all the apps that are not related to (1), so the result should be (4, quake) .
View 3 Replies
Apr 5, 2011
I know there are similar questions on stackoverflow - and I looked through them and think my issue is somewhat similar, but haven't been able to find a solution by looking at any of these other questions/answers.I'm getting the error when attempting to execute the following code:
Private Sub btnReserve_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReserve.Click
' Check that the room is still available.
Dim dbCheckOccupants As New pbu_housingEntities
Dim hall As String = CStr(Session("hall"))
[code]....
It is catching an error on this line:
Dim myID As String = GetID.First.id.ToString
As far as I can tell I'm not using multiple contexts?
View 2 Replies
Apr 7, 2009
I decided to iterate through the Data.DataTable and trimmed the values there.Utilizing SirDemon's post, I have updated the code a little bit:
[code]...
I know that on the DisplayMember line the .First.Item() part is wrong, I just wanted to show what row I am trying to designate as the DisplayMember.
View 3 Replies
Feb 17, 2011
I use the following code to fill the Table1 dictionary with the information found within the LINQ query.
Dim DB As New DatabaseDataContext
Dim Table1 As New Dictionary(Of String, Integer)
Dim Table2 As New Dictionary(Of String, Integer)
[code].....
View 3 Replies
Jan 23, 2010
I have the below code and it works fine, it's this way because I need to manually calculate some data before adding it to the Listview control.
Code:
Dim mList As List(Of ListViewItem) = mDataBase.GetRecords(LvwChecks, "CheckGroups", <Query>, GetType(CheckItem))
If mList.Count > 0 Then
[Code].....
View 6 Replies
Sep 14, 2011
I know its generally a big No-No to modify a collection that you are iterating through but unfortunately i didn't design the code that i'm trying to modify. All over the place the following is done:
for each log in Logs
logs.Delete(log.LogId)
Next
Delete pretty much just deletes the log from the database and removes it from the collection. Previously the Logs object was using a Non-Generic collection. I changed it to use a Collection(Of Log) so i can LINQify the object. Now every time i call next/.MoveNext is called after the first delete the following error happens:
InvalidOperationException:"Collection was modified; enumeration operation may not execute."
I understand why i'm getting the error but i don't understand why it never happened with the Non-Generic version. Is there anyway to get around this error? There really is no way i can take the time to change every place where the delete logs like this (codebase is large). Id like to just remove the code in the Delete function where it removes it from the current collection because i'm assuming no code does anything with the collection after its done but you know what happens when you assume.
View 3 Replies
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
Jul 6, 2010
I will start a new project, use the queries and dealing with databases using LINQ or SQl ,Which is better to start ???
View 4 Replies
Jun 5, 2008
I've recently ported my website from 2005 to 2008, and I'm using LINQ Queries to implement a search. The issue is that none of the fields are mandatory, so I've had to implement a dynamic LINQ Query (sic?). Here's the relevant code -
Public Function searchQuery(ByVal titleType As String, ByVal titleName As String, _
ByVal configMgr As String, ByVal lifecycle As String, _
ByVal CIType As String, ByVal recordsPerPage As String) As IEnumerable(Of
[code].....
View 2 Replies