Lazy Loading On A Collection Of Objects?

Mar 6, 2009

i have a sql query that can bring back a large number of rows via a DataReader. Just now I query the DB transform the result set into a List(of ) and data bind the Grid to the List.This can result occasionally in a timeout due to the size of Dataset. I currently have a three teir setup where by the UI is acting on the List of objects in the business layer.

View 3 Replies


ADVERTISEMENT

.net - Handle Lazy Loading/ConnectionString In Library?

May 4, 2011

I've created a solution that contains a single class library project and two web applications. My main problems are the connection strings. These are held/declared in the web projects and I'm having to pass them into the class library every time I perform any kind of data access. I sort of understand why I should do this so I'm going with it for the moment.This has now led me to a problem/question with lazy loading. I'm using lazy loading for the following property:

Public Property KeyRelationshipManager() As Employee
Get
If _keyRelationshipManager Is Nothing Then
_keyRelationshipManager = Employee.GetEmployee(_keyRelationshipManagerStaffNumber)

[code].....

I need to pass in the connection string to that function.This means I would need to pass the connection string in to the property every time I use it so I could pass it into the function.Is this correct? It doesn't 'feel' right to me because I'm going to have to adjust a huge number of functions and property and pass through the connections string.

View 1 Replies

Use Of Static Local Variables In Lazy Loading Property

Sep 19, 2011

I just recently learned about the uses of static local variables in VB.NET and wondered about it's potential use in lazy loading properties.

Consider the following example code.

Public Class Foo
Implements IFoo
End Class

[Code].....

As far as i can see, this has a few advantages over the usual implementation, primary your inability to access the variable outside of the property, as well as not having to use an additional variable.

My question to you is: Which of those is the "right" way to do it? I know that static variables have additional overhead, but is it bad enough to create, in my personal opinion, unclearer code that can be misused easier? How much performance do you lose compared to the "traditional" method? How does it matter for small classes compared to huge factories?

View 2 Replies

Collection Not Loading Correctly?

Jun 17, 2009

I have a issue with loading a collection. The issue is that when I load a collection up with multiple objects that the only items that are in the collection is duplicates of the last object that was added in. I was through the process of creating the new object and it is loading correctly but when it adds it to the collection, it changes all the prevoius objects with the current object. Here is the code that I am using. I have been messing around with this code for a day now and can't figure it out.

[Code].....

View 3 Replies

.net - Inheritance And Collection Of Objects?

Oct 21, 2011

we have 3 classes:Class S, class A, class B / A and B inherits S.A has a property A1 and B has a property B1.we also have a collection of objects that has A and B objects.ex.

Dim c as Collection = new Collection
c.add(new A)
c.add(new B)

Now we want to make a general object that will read from the collection.

ex .
Dim obj as S

how can we cast obj in order to see properties A1 or B1 according to the class;

View 1 Replies

Collection Of Objects Of Different Classes?

Dec 28, 2011

suppose I have a collection of objects of different classes (like controls in a form), and all of their classes have a MyMethod extension method. How do I have the appropriatemethod be called for each object, depending on its type?or example,

For Each ctrl In Me.Controls
'call ctrl real type's MyMethod
Next

[code]....

View 6 Replies

Collection Of Objects With A Unique Key

Jan 25, 2011

i've researched and written a generic class (all my objects are the same structure) and i'm was just working on the collection using a hash table but i've just read a comment within (url...) in this forum...that we shouldn't use hashtables at all with vs2008.i actually need and object collection that contains other object collections within them.the application i'm trying to write is relatively simple (but i'm new to vb.net)it keeps track of the time for weight lifting training/workouts.a workout consists of 'say' a bench press, military press, curls, dead lift, etc within the "bench" you have 1,2, or 3 sets (how many times you do "the bench", within a set you have 1,2,3 or 4 lifters, each lifter does reps.then it starts over with military press..i guess i could base it on a treeview type structure (with parent child type relationships) but i usually think in terms of collections it appears that a collectionbase has no key and i'd have to keep track of them on my own...

View 2 Replies

Lifetime Of Objects In A Collection

Nov 16, 2010

I'm trying to figure out the lifetime of the tmpTabPages in the following bit of code. Lets assume the form has an empty TabControl named MyTabControl, that there's a collection of strings called NameCollection.

[Code]...

View 4 Replies

Run A Method On All Objects Within A Collection?

May 29, 2009

So I have a collection of Razzies created from a Collection of Bloops. I retrieve this collection using a Linq query. Reference:select-certain-properties-into-another-object for the query.I would like to know if it is possible to run a method on all of the newly created Razzies before returning the collection, or even right after, just without using a for-loop.

I tried ths:
Dim results = From item In bloops _
Select New Razzie() With _

[code].....

View 6 Replies

VS 2008 Loading SQL Objects?

Jan 5, 2012

I am creating a sports bet program and have set up a database in sql server 2008 R2 with results for games including wagers, odds etc. I now want to display this data in a range of listboxes, textboxes and labels in my VB.Net program.I am quite happy to play around and learn myself however I would love it if someone could get me started by completing one of the simpler labels. This label has to display the entry in Team One in labelTeamOne.

show me how to do this? I have already imported the dataset using the database wizard so all I need is the code.

View 5 Replies

.net Collections: Copy Objects From One Collection To Another?

Nov 24, 2011

I'm implementing a customized Graph algorithm in vb.net, and I'm having the following problem:

Supose the code:

dim col as new collection
dim myC as new system.collections.genericList(of myClass)
dim obj1 as new myClass
dim obj2 as new myClass

[code].....

'In the next statement, the myC2 inside col collection will be decreased to contain 'only obj1, like myC. I supose this is for myC and myC2 contains only a pointer to 'objects obj1 and obj2 as well col contains pointers to myC and myC2 myC.remove(obj2)'The problem is that I have to only copy myC to myC2, like a ByVal argument in a function,'instead a ByRef argument, in order to mantain a copy of objects in myC2 while these 'objects should be removed from myC. How should I do it?

View 2 Replies

A Property In A Class Is A Collection Of Objects

Jan 29, 2009

Thought I had got this sorted earlier but unfortunately not. A property in a class is a collection of objects.

[Code]...

View 4 Replies

Creating A String From A Collection Of Objects?

Oct 4, 2010

I have a question. I have a class of Cars that I need to display in a simpli-ish string if they will be sold or not base on their number.

[Code]...

I'd like to display a simple string like this:Cars to be sold: 1, 3-5, 7-8, 11, which is based of the .Sell value.Is there some kind of heuristic to create this kind of string in .NET or is it just a bunch of for/each and if/then and redimming of arrays?

View 2 Replies

How To Create Accumulator For Collection Objects

Apr 23, 2012

I am trying to maintain a total for multiple collection objects in a class. When I create a new object, it resets the total to zero, only adding the current value being passed to the function. I have tried to use a static variable, create a second variable to hold the old total while adding the new value. The base class holds the total value, while the sub class creates the new object that holds information. I am passing the new value to a function in the base class adding the new value to the total when each new record is created.

[Code]...

View 1 Replies

Pass Collection Of Objects To BackgroundWorker?

Nov 19, 2010

I have an object of type Dictionary(Of Int16, Polygon) and which contains sometimes up to 15 or so Polygons that i am creating bitmap files with the Polygon. This can take like 20 seconds sometimes so i was trying to pass the full Dictionary to background worker as an argument but i get an issue when trying to access each individual Polygon inside of the Dictionary because the Polygons still belong to the UI thread. How can I access the Polygons inside the Dictionary with the backgroundworker?

Dim worker As New BackgroundWorker
AddHandler worker.DoWork, AddressOf MeasurePolygons
AddHandler worker.RunWorkerCompleted, AddressOf WorkerCompleted
worker.RunWorkerAsync(PolygonCollection)

that is how im calling the thread. PolygonCollection is the Dictionary(Of Int16, Polygon) that contains all the polygons that i will be creating a bitmap file out of.

View 9 Replies

Sort Of A Collection Of Class Objects?

Feb 28, 2012

I'm having problems doing a sort of a custom collection. The collection is Device Classes which is a collection of Device Class. My sort does not produce an error but the treeview control shows nothing. I am not sure what I am missing. I'm guessing just a simple sort won't work here but I don't know what I'm missing in my code. Here's the code that creates the collection

[Code]...

Simply sorting the treeview will not work because it throws off the display of related info for a given device in listview controls. The collection itself needs to be sorted before the data is added to the treeview.

View 6 Replies

SQL Command Objects Paramaters Collection

Sep 16, 2010

I was just curious as to whether after you have added all of the Parameters to the SQL Command Parameters Collection. Is there a convenient way to iterate or loop through the Parameters and make Assignments to the SQL Command Parameters Values Property?

View 2 Replies

.net - Binding A Collection Of Objects To A ComboboxColumn In A DataGridView?

Jan 24, 2012

I have a GUI which allows the user to select a report to view/edit. When the user selects a report, it shows the Items in the report. The Item has many properties - most of which are binding properly. One of the properties is Owner, and this is bound to a ComboBoxColumn.

Report

Items

Owner

I have done something very similar to this a few times and had no problems when I set the DataPropertyName, DataSource, ValueMember, and DisplayMember. The only difference is that this time instead of the Item type having an OwnderID it actually has an instance of the Owner object.giving the items bound in the list a self-referencing property that allows them to return themselves for the purposes of setting the ValueMember.However, When I bind it this way:

OwnerColumn.DataPropertyName = "Owner"
OwnerColumn.DataSource = ownersBindingSource1
OwnerColumn.ValueMember = "Self"
OwnerColumn.DisplayMember = "OwnerName"

I get a lot of errors like: Unable to cast object of type 'System.String' to type 'Owner'.

and:

The following exception occurred in the DataGridView:

System.ArgumentException: DataGridViewComboBoxCell value is not valid.To replace this default dialog please handle the DataError event.I was able to get around some of these errors by binding it like this:

OwnerColumn.DataPropertyName = "Owner"
OwnerColumn.DataSource = ownersBindingSource1

and also by making the ToString function on the Owner display the OwnerName property. This seems pretty hacky though - and I think I'm misunderstanding something fundamental as it still does not function properly.

View 1 Replies

Collection To Place These Objects In For Easy Reference?

Nov 11, 2011

I have an error while using a collection that has been stumping me for years.I wrote a class to allow users to write equations in a txt file using RPN (stack based notation).The class runs through a select statement while reading the equation and then ends up with a final number as the answer. I have a collection to place these objects in for easy reference. For whatever reason I get random object reference not set to an instance of an object errors when there is nothing in the program that would remove objects from the collection, kill objects, or change the collection in any way. It is possible for one thread to call the calculate function while another thread calls the CurrentValue property. I'm not sure if this could be causing the error, but once it happens I get an error every time the program enters that code until I run out of memory.

[Code]...

View 4 Replies

Store Objects With Key In Some Sort Of Collection/Dictionary?

Jun 10, 2012

I need to Store Objects with Key like:

Key: <Fontname & FontSize> / Object: <Font Object>

Example content:

ArialRegular8 | <Corresponding Font Object>
ImpactItalic10 | <Corresponding Font Object>
TimesRomanRegular12 | <Corresponding Font Object>

These font types come from an external library, the real type is DocumentFont, I prefer not to store just values and recreate the font object later, so I need to store the object, and i want to be able to call Contains() later without looping. like for example Dictionary (of T Key, T Value), is this the best option? Also, to be able to call Contains(), i will have to overload function Contains() using an Interface or this is already built-in in some Collections / Dictionaries when using a String as Key?

View 3 Replies

Place Dynamically Generated Objects In An Array (or Collection)?

Apr 11, 2011

I created a custom class for a custom object. I instantiate like so[code]...

Now, I have two problems. First, right now this is just overwriting the same object properties, again, and again. I need to somehow dynamically name the object. Then, I need to place these objects in an array so I can iterate through them...

View 1 Replies

VS 2010 Multi-threaded But Using A Global COLLECTION Of Objects?

Mar 19, 2012

I've got a multi-threaded app - that is using a global COLLECTION of objects.I'm starting to think that objects - when copied to objects - are really just reference pointers to the "single object" in memory - as they would be in JAVASCRIPT (too many languages At any rate - this code - when taking the object from the collection to work with is it making a new object to play with or is it working the single object that actually resides in the collection?

[Code]...

View 16 Replies

Use A Custom Collection Derived From CollectionBase To Store Our Business Objects

Feb 26, 2009

We use a custom collection derived from CollectionBase to store our Business objects

[Code]...

View 3 Replies

Dereferencing Objects - Make CopiedCollection A True Copy (not A Reference) To The Listbox1.Items Collection?

Jun 30, 2010

Okay I've been wondering about this for a while now, but whenever you assign variable values to objects they tend to just become references to the original object

For example:

Dim copiedCollection As ListBox.ObjectCollection = ListBox1.Items
For Each L As String In copiedCollection
If L = "Goodbye" Then ListBox1.Items.Remove(L)
Next

As soon as it encounters the string "Goodbye" and removes the item from the listbox, the program will throw an error saying the the collection (copiedCollection) has been modified. How can I make copiedCollection a true copy (not a reference) to the Listbox1.Items collection?

View 14 Replies

Lazy Load Variable Being Assigned

Jan 4, 2010

I have a strange problem with a lazy load property in my class.[code]The problem i have is that when i create a new instance of the class the value of 'mMarksLoaded' is true however when i put a break point on this section of code, execution is never interrupted.Is it possible that the .net framework is accessing this property behind the scenes?

View 12 Replies

Error With The Using Statement And Lazy Initialized Property

Dec 1, 2009

The code below will throw an InvalidOperationException: The ConnectionString property has not been initialized. The exception is thrown at the line calling Connection.Open() in the Load method. If I use the try-finally statement instead of the using statement, everything works correctly. Can anyone explain why the exception occurs with the using statement?

[Code]...

View 2 Replies

Base Class Collection With Sub Class Objects

Jul 19, 2010

[code]The reason that this is a problem is that this is a collection of EventBase objects, but I'm trying to populate it with child classes instead. For example, I might have a JumpEvent class that inherits EventBase, and this is being put into the EventBaseCollection. That means that value.GetType() returns the type of JumpEvent, which as you might guess does not equal the type of EventBase.The goal of course is to simply loop through all of the various events without having to know anything about the sub-classes. Is there a way to determine the type of the base class so that the OnValidate call will work? Or is this just the wrong way to go about it altogether?

View 2 Replies

.net - Storing Subcollections (filtered Versions Of The Main Collection) Inside The Collection As Cache?

Jan 15, 2010

Is it good practice to store sub-collections of item X inside a parent collection of item X for caching 'filter-queries' which are performed on the parent collection? (They won't be used together (as in color AND type).) Or is it also ok to just Loop over the collection and return the correct entities in a temporary collection?

[Code]...

View 1 Replies

C# - Edit List Collection : Error Note Collection Was Modified - Enumeration Operation May Not Execute?

Sep 7, 2011

I have the following classes:

Product, Service and OrderItem

Product and Service must inherit OrderItem. So basically I want to store OrderItem object in my shopping cart and these object are store in a list.

Public MustInherit Class OrderItem
Private m_enuItemType As TypeOfItem = TypeOfItem.None
Private m_strUserID As Integer[code].....

View 1 Replies

Make A Custom Collection That Take Advantage Of The Collection Editor?

Feb 8, 2010

I have been researching for a couple of days now and to no avail. Does Anyone know how to make a custom collection that take advantage of the collection editor? I would like to be able to have 3 Color Values, 1 Boolean and 1 String.

View 15 Replies







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