Sorting Datagrids loading from EntityCollection

Posts   
 
    
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 11-Sep-2006 17:35:20   

Hello gurus of LLBLGen Pro please guide me to the right path.

I have two tables in two different databases. Table A and B. I am displaying table A (using DataGrid on a web page) and getting a count of related record from table B. I load both into the grid. So I have a record from table A and a count of records of table B. I would like to sort by number of records on table B. Is there a way to add a dynamic field on table A so I could stash the count from table B? I have done a work around where I just added a field on table A that I do not use, basically a temporary field. Is there a cleaner way of doing this on code? I would like to avoid changing the generated code, or using the partial keywork from .Net 2.0.

Am I thinking this the wrong way? Please could you point me in the direction of enlightenment?

Thank you, Bruno Valle

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 18:01:08   

Hi,

you may use a cross table typedlist, with a relation from table A to table B, and an aggregated field to perform the count.

Once the count field is defined, you may use it in your sortexpression.

Have a look in the manual for the corresponding explanations and examples about TypeLists and aggregates.

That also let me think that you should be careful when you talk of "tables". As you can see, LLBLGen manipulates Entities, TypedLists, DataTables etc... and you have to be aware of what distinguishes them.

Hope that helps

bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 11-Sep-2006 20:56:10   

Hi Jessynoo

I was readying about TypeLists, am I correct on stating that TypeLists are read only? I would need the power to change the entries that are been displayed, should I be using another method to accomplish my goal?

Thank you in advance, BrunoV

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 12-Sep-2006 13:40:32   

bvalle wrote:

Hi Jessynoo

I was readying about TypeLists, am I correct on stating that TypeLists are read only? I would need the power to change the entries that are been displayed, should I be using another method to accomplish my goal?

Thank you in advance, BrunoV

Hi,

I use typedlists for my reports and almost I have to change the generated code to mark all the columns as ReadOnly = False, this allow me to change any column value or add new row the the typedlist.

I do the following:

Dim col as Datacolumn

For each col in Me.Columns col.ReadOnly = False Next

I do not remmeber right now the name of the method inside the typedlist generate code where I put this code; but if you need it I can go and check the name.

bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 12-Sep-2006 16:53:16   

Thank you for your comment.

The problem is not making the DataGrids as read only, it is the fact if I change a TypeLists (which by the manual does not seem to be possible) when I save the changes no changes will be saved.

Huh perhaps I am not explaining this correctly.

Basically I have two tables in two different databases, I need the count of one and the entity collection from the other, and they have a serial number, if you will, as association. I need to populate this DataGrid and be able to modify data on the DataGrid and be able to apply to the table on the database without doing another lookup.

Basically I am trying to do the following TSQL using entities, fetchets, or whatever tool necessary on LLGLGen Pro.


SELECT Count(*) 'Enable', S.*
FROM ZSDB.dbo.tblSiteAssemblyPoint P
JOIN DVM_CI.dbo.tblSite S 
ON S.CustomerSiteID = P.SiteID AND P.ProcessEnabled = 1 
GROUP BY ProcessEnabled, SiteID, SiteSerialNumber, CustomerSiteSerialNumber, CustomerSiteID, SiteTemplateID, SiteTemplateTypeID, SiteStatusID, DefaultHistoryInterval, LocationID, S.HistoryID
ORDER BY 'Enable' DESC

Any ideas?

Thank you, BrunoV

Rogelio
User
Posts: 221
Joined: 29-Mar-2005
# Posted on: 13-Sep-2006 05:50:14   

Hi,

The typedlists that I change are never saved back to the database, to save to the database I use entities. I do not see other way that adding a custom field in the generated entity code and getting the count for each record as you are doing.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Sep-2006 07:41:54   

2 options come to my mind.

1- To create a database View "A_VIEW" -> (A_ID, CountOfB) - Then map this view to LLBLGen Pro as an Entity - Use the designer to define a relation between A_VIEW and AEntity - Use the designer to define a field mapped on related field in AEntity that mapps the A_VIEW.CountOfB - Fetch the AEntity collection with prefetchPath to the A_VIEW, so the mapped field CountOfB gets loaded. - Use this field in the sorting.

2- Create a custom property for AEntity, that returns the count of the related B collection. - use prefetchPath to BEntity when fetching the A collection so the related collection gets loaded. - use the custom property in your sort.

Option 2 is the easiest to me.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 13-Sep-2006 11:18:58   

To clarify: 'custom property' means a new property in code added to the entity class. simple_smile (So no confusion exists between custom properties added as name-value pairs to the entity in the llblgen pro designer wink )

Frans Bouma | Lead developer LLBLGen Pro