Avoiding entities

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 29-Apr-2005 15:49:48   

Hi,

I need to bind to a drop down list. So I just need the key field and a text field from a database table. But the table has many other columns and I don't think its good to return all the data for each and every row just to use an integer and a line of text. Yet, this is what will happen if I bind to a list of generated entities which reflect the table.

So the next step is to define a view but then I have to generate another entity to relect the view.

So seen as writing a view is almost the same as writing a retrieval stored procedure, I figure that I'll define a stored procedure and have LLBLGen return a dataTable like this...


DataTable resultSet = RetrievalProcedures.GetCategories();

So I avoid returning uneeded data and avoid another entity object and I'm not going to miss the strong typing because the table is going to be plugged into a drop down list anyway.

Does this sound like a good idea?

sirshannon
User
Posts: 48
Joined: 26-Jun-2004
# Posted on: 29-Apr-2005 16:59:08   

That is how I usually deal with DropDownLists when I am binding to collections that are much larger than the 2 columns I need.

Not saying it is right, but it is the easiest way I've found.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Apr-2005 17:26:30   

Create a dynamic list. See the typedlist/view documentation in the manual which discusses the creation of a dynamic list.

An example: fetching the CustomerID and the CompanyName from the customers table:

ResultsetFields fields = new ResultsetFields(2); fields.DefineField(CustomerFieldIndex.CustomerID, 0, "CustomerID"); fields.DefineField(CustomerFieldIndex.CompanyName, 1, "CompanyName");

and then you just have to fetch it using existing typed list fetch logic, so in SelfServicing this will be: DataTable results = new DataTable(); TypedListDAO dao = new TypedListDAO(); dao.GetMultiAsDataTable(fields, results, 0, null, null, null, true, null, null, 0, 0);

or if you're using adapter: DataTable results = new DataTable(); DataAccessAdapter adapter = new DataAccessAdapter(); adapter.FetchTypedList(fields, results, null, 0, null, true, null);

As you can see, you can use filters, group by clauses and what not, even paging simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 29-Apr-2005 18:48:28   

That's cool.

Do you have an idea of the difference in performance between fetching a Dynamic List and fetching a collection of entities whose class is generated from a view?

Cheers,

Ian.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Apr-2005 19:23:05   

With a dynamic list, in this case the query is smaller (just 2 columns) and the amount of data is smaller (just 2 columns simple_smile ). So the dynamic list is faster. Also it doesn't have to create an object for each row, just a datarow in a datatable.

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 01-May-2005 01:33:32   

Yes but what if both types of retrievals returned the same data using the same query? Which would be faster? I suppose I could test this myself but perhaps you already have researched this? smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 01-May-2005 10:33:29   

Ian wrote:

Yes but what if both types of retrievals returned the same data using the same query? Which would be faster? I suppose I could test this myself but perhaps you already have researched this? smile

Then fetching into a datatable is somewhat faster, as a datatable doesn't have to create a full object out of each row read simple_smile .

Frans Bouma | Lead developer LLBLGen Pro