.net - Unexpected IQueryable Value After ForEach Iteration?

Apr 15, 2012

I'm flummoxed I'm using VB.Net, Linq, and a DataContext. My DataContext contains a table 'transactions'.

I first declare an IQueryable(Of transaction) and assign it to nothing. I build a predicate in a foreach loop and use a transactions.Where(predicate) to assign the IQueryable a value. If I do an IQueryable.ToList(), I get a number of items in the collection.

However, on the next iteration of the loop, the IQueryable.ToList() gives me 0 items.This is driving me crazy. I tried to use the LINQ to SQL Debug Visualizer with VS2010, (I recompiled the 2008 version with the new reference) but no dice - I can't see the SQl generated or what's inside the IQueryable.

[Code]...

View 2 Replies


ADVERTISEMENT

.net - "Using The Iteration Variable In A Lambda Expression May Have Unexpected Results"

Jun 27, 2012

Edit: Here is a much more simpler example of this issue (i've deleted my original question):

Dim numbers1 As New List(Of Int32)({1, 2, 3})
Dim numbers2 As New List(Of Int32)({3, 4, 5})
For Each n1 In numbers1
' no warning '
Dim contains = numbers2.Contains(n1)
Next

[Code]...

The local variable number1 is redundant and makes the code less readable as @Meta-Knight already has emphasized. Note: All three ways are safe and give the correct result.

View 2 Replies

Get: "iteration Variable In A Lambda Expression May Have Unexpected Results"

Mar 1, 2012

Possible Duplicate:Why is it bad to use a iteration variable in a lambda expression.why do I get: "iteration variable in a lambda expression may have unexpected results"? Suppose I have the following code:

[Code]...

View 2 Replies

IQueryable OrderBy Error: Cannot Order By Comparer

Sep 14, 2011

I'm trying to sort a IQueryable dynamicaly.

Dim activities =From a In db.VW_Activities Select a
activities = activities.OrderBy(Function(a)
New ActivityComparer(SortFields(0).Sort))
definition of SortFields:

[Code]...

View 3 Replies

Sql Server - Read Data From A Database Using LINQ To SQL In VB Using An IQueryable?

Dec 2, 2011

I know how to select items from an array with LINQ, but what I can't figure out how to do is access a database using an IQueryable. I connected the database to my project, added two classes from the database to the "LINQ to SQL" .dbml file and saved it. In my programming assignment, I am not supposed to create a data source (table thing) to display the data, but update my own interface manually. In order to do it, I was told to instantiate this:

Private dogs As System.Linq.IQueryable(Of Dog)

(Dog is a class that I added to my .dbml file from the database file)Also, I am told it involves using a method

.AsEnumerable.ElementAt(index As Integer)

View 1 Replies

Value Of Type 'System.Linq.IQueryable(Of Date?)' Cannot Be Converted To 'Date'

Dec 6, 2011

I'm trying to get datetime value but here is issue with nullable datetype.

Public Function GetDate(ByVal kodg As Integer) As DateTime
Dim g = From dt In db.xDates _
Join f In db.xGrafiks On dt.КодД Equals f.DateKod _

[Code]....

View 1 Replies

Value Of Type 'System.Linq.IQueryable(Of Integer)' Cannot Be Converted To Integer?

Aug 11, 2011

I am new to EF Linq and I have been struggling with this query for a few days. From reading this forum, I have managed to get this far:

Dim noPic = (From f In myEntities.FriendLists
Where (f.UserID = Profile.ID)
Select f.FriendID).Except(From g In myEntities.GuestLists
Where g.EventID = _id
Select g.FriendID)

[Code]...

I am trying to get everybody from the FriendList who is not already on the GuestList to display in a Repeater control. After reading the forum I was able to append .First() to noPic at the myNoPic declaration and finally get a result but that only gave me the first element. Does anybody have any advice on how to accomplish this?

View 2 Replies

.net - Operator '=' Is Not Defined For Types 'Integer' And 'IQueryable(Of Integer)'

Aug 3, 2010

This is giving me a headache. I have this link query here that grabs an ID

Dim mclassID = From x In db.SchoolClasses Where x.VisitDateID = _visitdateID Select x.ClassID And then later on I have this linq query

ViewData("Staff") = From t In db.Staffs Where t.ClassID = mclassID Select t

I've tried quite a few things but to no avail. I've attempted casting, converting, Is operand, etc.

View 5 Replies

How To Iteration In Vb

Jun 26, 2011

i am developing a program in visual basic 2010, it involves a non- linear iteration of one of the two variables with a step of .00 and a match at the .000 (3rd) decimal placethere cannot be an exact match between the 2 variable's values but i need the iteration to stop at the nearest possible value.

View 6 Replies

Foreach In Faster Than In C#?

Mar 12, 2009

My co-worker said that in a previous interview, he learned that foreach is faster in VB.Net than c#'s foreach. He was told that this was because both have different CLR implementation.

Coming from a C++ perspective, I'm curious on why this is and I was told that I need to read up on CLR first. Googling foreach and CLR doesn't help me understand.

Does anyone have a good explanation on why foreach is faster in VB.Net than in c#? Or was my co-worker misinformed?

View 5 Replies

How To Use Parallel.ForEach

Apr 15, 2010

tell how to form this to the correct Syntax?ere the sample in sequential form:ForEach ctrl AsCheckBoxIn tblCKBoxCollection.Controlsctrl.Checked =

View 1 Replies

Iteration Using The Do-Loop?

Nov 15, 2011

I just can't seem to understand when i am suppose to put Accept outside the LOOP and when i'm suppose to Accept inside the LOOP at the beginning.

View 4 Replies

Using The Iteration Variable?

Jan 23, 2012

Is the warning I am receiving about using the iteration variable in this line a concern.

Dim reportdataforpage = (From reportvar In reportdata Where reportvar.reportpage = pagenum)

View 5 Replies

.net - Action(Of T) In VB In List(Of T).ForEach?

May 21, 2009

I have searched high and low for documentation on how to use this feature. While the loop I could write would be simple and take no time, I really would like to learn how to use this. Basically I have a class, say, Widget, with a Save() sub that returns nothing. So:

Dim w as New Widget()
w.Save()

basically saves the widget. Now let's say I have a generic collection List(Of Widget) name widgetList(Of Widget) and I want to run a Save() on each item in that list. It says I can do a

widgetList.ForEach([enter Action(Of T) here])

....but how in the F does this work??? There is no documentation anywhere on the intrablags.

View 5 Replies

Anonymous Methods In .NET - Foreach?

May 16, 2011

I try to replace the classic For Each with the LINQ ForEach method in VB.NET

Dim singles As New List(Of Single)(someSingleList)
Dim integers As New List(Of Integer)
For Each singleValue In singles

[code]....

How should I correctly do it (using anonymous methods = without declare a new function)?

View 2 Replies

Foreach - Each Loop On A 2D Array In .NET

Oct 14, 2011

I'm writing a loop to go through the first array of a 2D loop, and I currently have it like this:

For Each Dir_path In MasterIndex(, 0)
'do some stuff here
Next

But it's giving me an error, saying it expects an expression in the first field. But that's what I'm trying to do, loop through the first field. How do I fix this? What would I put in there?

EDIT: to clarify, I'm specifically looking for the 0th element in the subarray of each array, that's why that second field is constantly 0.

View 2 Replies

Iterating A List With ForEach

Mar 1, 2010

I have a list like this

[Code]...

How can I iterate the list with ForEach to get one string with the emails like this [URL]

View 5 Replies

VS 2008 - Using 2d Array With Foreach

Aug 24, 2010

is it possible to use foreach with a 2d array?

View 8 Replies

VS 2008 Getting Certain Info In Foreach

Aug 30, 2009

What i'm doing is getting values from some html, i use a regex to retrieve all the fields, but there are some fields brought back i don't need (4 out of 11) i know the names of these fields, but was wondering if there was a way i could filter out the ones i don't need in the foreach:[code]

View 5 Replies

Assign One Value To Whole Array Without Iteration Through It?

Aug 25, 2009

how to assign one value to whole array without iteration through it? for example a i have pArray (5000,5000) =1 where all members off array = 1.

View 2 Replies

DataGridViewColumn Iteration Speed?

Jun 13, 2012

I have noticed that when iterating DataGridViewColumns, the speed is greatly reduced if the columns are visible.

For Each col As DataGridViewColumn In cData.DataGridView.Columns
col.Visible = visible
Next

If visible is set to false (and all columns are all currently visible), iterating 264 columns takes around 0.35s, however, if visible is set to true (and all columns are currently invisible), the same process takes around 30s.Does anyone know what would be causing the extra time?Could it something internal to the DataGridView Control?

View 5 Replies

Does A For-Each Loop Have An Iteration Count

Jun 18, 2009

Does a For-Each loop in VB have an iteration count, or would I have to do that myself?

View 5 Replies

How To Skip To The Next Iteration In A For Loop

Nov 10, 2009

I've got a for loop. In my loop , I've got a condition , and if that condtion is not met, I need to move on to the next iteration.

So if I have :
For Each txt As Control In tbcell.Controls
if TypeOf (txt) Is CheckBox Then

[code]....

View 3 Replies

Iteration Of Class Variables?

Sep 23, 2011

Background: I am working on an ASP.net project that basically fills out a form from user input. The generated form (for reasons which I have no control over) must be a JPEG or TIFF. So the user fills out the web form, which takes all of the input values and meges them into a blank image (jpeg) of the form. Using System.Drawing, it merges all of the text onto the form at designated Points. The points are defined as variables which are modified at runtime to compensate for the resolution of the image (in case it get modified/re-generated at a different dpi). All of this is working fine.

Problem: Currently I have a Sub that determines the dpi of the master image, then adjusts the Points accordingly. However, there are ~50 variables that have to be adjusted. So currently I have the Sub go thru each point variable and manually adjust the X & Y values. I have been working on a Sub that will iterate thru all of the Point variables and do adjustment. Here's a functional sample of what I have working:Imports System.Drawing

Partial Class test Inherits System.Web.UI.Page

[Code]...

This works...sort of. It allows me to grab each variable and modify it, but only in the instance. The original variable in the class is unchanged. Which means that when the program gets to the point where it's drawing text to the image, the points are unmodified. my basic question is: Is it possible to modify the original variable using this sort of process? If not, is the best way to use these modified values to declare the new class instance at a global level, then have the Sub that draws the text use the instance versions of the variables?

I realize that I could define all of the points in an array which would be easy to loop thru and update, but I've named each point variable something meaningful to correspond to the related text to be drawn.

View 1 Replies

.net - Parallel.ForEach Local Storage?

Aug 3, 2010

I recently changed a For Each loop to a Parallel.ForEach loop. I'm concerned about an object being declared outside the loop but assigned while iterating in the loop. Here is the simplified code.

Dim results As ModelResults
Dim noResultsModel As New List(Of ModelResults)
Dim lock As New Object
Parallel.ForEach(_modelEngines,
Sub(model)

[Code]...

Is there a potential race condition with the results object? Would anything be different if I moved the declaration of results into the for loop?

View 1 Replies

Changing The Value Of An Array Through A Foreach Statement?

Jun 13, 2012

I am making a program that automates the seperation of a csv file. We read the csv in through and then assign the "line" using a split command to an array. After that we go through each "cell" in the array and put an = in front because this causes leading zeros not to be lost. Here's the code.

arLine = line.Split(replace)
For Each cell As String In arLine
cell = cell.Replace(",", "")
cell = String.Format(cellFormat, cell)
Next

arLine is the array and replace is the delimiter, in this case a pipe not that it matters.'

When it goes through, the arLine is correct but the values in each cell are not changing, any thoughts? newer to VB.net and need direction

View 2 Replies

Convert Collection.foreach From C# To Program?

May 12, 2009

In C# i just put the method in the parentheses that i want to run on each row of the collection, but it isn't working in VB.NET.[code]...

View 1 Replies

DataGrid View Creation Via ForEach

Apr 18, 2012

I am having an issue extracting the value from every row in column "MobileID" within a table named "dt" that is within a dataset named "ds".Here is how the dataset and datatable are created.[code]

View 1 Replies

Dynamically Add Checkboxes In A Foreach Loop?

May 8, 2009

I have the following for each loop which loops through a registry key and reads all the values:

Dim returnValue As RegistryKey = Registry.LocalMachine.OpenSubKey("SOFTWAREMicrosoftWindowsCurrentVersionRun")
Dim keyname As String = "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun"
Dim values() As String = returnValue.GetValueNames

[code].....

What I am trying to have been highlighted in bold.. Each time the loop executes and reads a value from the registry, I want the code to create a checkbox which has a unique name and text according to the value that was read... So the number of checkboxes will depend on number of values that is got from the registry...But this doesn't work. It only creates one text box and the text of the textbox is also incomplete...

View 7 Replies

VS 2008 - Second Foreach Loop Runs

Jul 9, 2009

I have the following Method:

CODE:

Everything is working fine except for one part. The part where the second foreach loop runs. If I only have one plugin installed it puts 2 entries in the list. The reason is because it has 2 rows and it is adding it twice. I know what the issue is I just am drawing a blank right now.

View 11 Replies







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