How to achieve "Select Distinct From xxx" in LLBL collection classes

Posts   
 
    
yj
User
Posts: 39
Joined: 07-Aug-2007
# Posted on: 24-Aug-2007 05:40:24   

ASP.NET 2.0 C# LLBLGen Pro 2.0.0

I have a problem here when i try to use the collection class to bind it to my drop down list. I would like to display a list of distinct values, e.g. currency, which have duplicates from a CountryCollection inside the LLBLGenProDataSource component. I would like to know how can i eliminate the duplicates in this case? How to perform the "SELECT Distinct Currency from Country" statement here? Thanks for the help again

Regards, yjpan

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Aug-2007 09:28:41   

Since you are fetching one column, then use a DynamicList. And specify false for the AllowDuplicates parameter of the fetch method.

yj
User
Posts: 39
Joined: 07-Aug-2007
# Posted on: 30-Aug-2007 02:56:59   

Walaa wrote:

Since you are fetching one column, then use a DynamicList. And specify false for the AllowDuplicates parameter of the fetch method.

hi walaa, i have been using the dynamicList as datasource for my drop down list, however the duplicates still persist. i had tried creating a typedList also, and using the LLBLProDataSource control, setting the AllowDuplicates properties to "False", yet i still get the duplicates, am i missing out something here? Below is the code i wrote for my dynamicList:

    ResultsetFields fields = new ResultsetFields(1);        
    fields.DefineField(RCountryFields.CurrencyCode, 0, AggregateFunction.None);

    DataTable dtCurrency = new DataTable();
    TypedListDAO dao = new TypedListDAO();
    dao.GetMultiAsDataTable(fields, dtCurrency, 0, null, null, null, false, null, null, 0, 0);

The table structure and sample data for my RCountry table are: Country_Code Country_Name Currency_Code US United State USD UK United Kingdom Euro FRN France Euro AU Australia AUD

What i intend to achieve is to create a drop down list containing only the data in Currency_code column, and if you can see there are 2 entries of "Euro" here, if by using normal SQL, a SELECT Distinct will easily solve the problem, how can this be done in LLBL? Thanks again.

yj
User
Posts: 39
Joined: 07-Aug-2007
# Posted on: 30-Aug-2007 03:16:40   

To correct something from the message above, I would say that the Datatable does work. When i show the .count of the datatable, it shows 3 from the sample data i have above. However, the problem is i m using the drop down list in a gridview, it is tedious to do manual binding and i have not been able to achieve the binding using datatable. I tried creating a typedlist, and use the LLBLProDataSource control to bind it with my drop down list. Now that the AllowDuplicates is set to false, yet it still show 2 entries of "Euro" in my drop down list (even after rebinding), what am i missing here?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Aug-2007 08:15:29   

Weird disappointed Could you please post the LLBLGenProDataSource and DDL declarative ASPX?

David Elizondo | LLBLGen Support Team
yj
User
Posts: 39
Joined: 07-Aug-2007
# Posted on: 30-Aug-2007 10:00:53   

daelmo wrote:

Weird disappointed Could you please post the LLBLGenProDataSource and DDL declarative ASPX?

LLBLGenDataSource ASPX:

<llblgenpro:LLBLGenProDataSource ID="dsCurrency" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="SBVS.CollectionClasses.RCountryCollection, SBVS" AllowDuplicates="False"> </llblgenpro:LLBLGenProDataSource>

DDL declarative (inside a gridview and the column turned into template) <asp:TemplateField HeaderText="Currency" SortExpression="Currency"> <EditItemTemplate> <aspsmile ropDownList ID="ddlGrvCurrency_E" runat="server" DataSourceID="dsCurrency" DataTextField="CurrencyCode" DataValueField="CurrencyCode" SelectedValue='<%# Bind("InvCurrencyCode") %>'> </aspsmile ropDownList> <llblgenpro:LLBLGenProDataSource ID="dsGrvCurrency" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="SBVS.CollectionClasses.RCountryCollection, SBVS"> </llblgenpro:LLBLGenProDataSource> </EditItemTemplate> </asp:TemplateField>

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Aug-2007 10:22:58   

UK United Kingdom Euro

First of all UK uses Pounds (British Pound or Pound Sterling), not Euro I guess this wrong information upsets your program wink

Now back to the issue:

I tried creating a typedlist, and use the LLBLProDataSource control to bind it with my drop down list. Now that the AllowDuplicates is set to false, yet it still show 2 entries of "Euro" in my drop down list (even after rebinding), what am i missing here?

Here you say, you use a TypedList

<llblgenpro:LLBLGenProDataSource ID="dsCurrency" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="SBVS.CollectionClasses.RCountryCollection, SBVS" AllowDuplicates="False"> </llblgenpro:LLBLGenProDataSource>

Here you are using an EntityCollection.

And there is a big difference between the 2 approaches. Fetching an entityCollection, fetches complete rows by default, not just one column. And your table actually contains 4 distinct rows.

Try using a TypedList of one column.

Please refer to the LLBLGen Pro manual for TypedLists. And examine the generated query for each case to know what's going on. (ref. to the troubleshooting section of the manual)

yj
User
Posts: 39
Joined: 07-Aug-2007
# Posted on: 30-Aug-2007 11:33:04   

hi walaa,

thanks for the reminder, actually the data are quite dummy.... too dummy in fact.. hehe anyway, thanks for pointing out the problems, i m able to solve it now using my typedlist. Just that i noticed something strange, that for the LLBLProDataSource, i originally used a EntityCollection as the datasource, and later on changed to a TypeList. It seems that even though i used the "Configure Datasource" to configure, the output seems not the things that i want (it still binds back to the EntityCollection) I have to delete the control and recreate another one to achieve what i need. Anyway, thanks again as another problem solved! hooray!