Binding an Entitly Collection to a gridview via n:m relationship

Posts   
 
    
f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 12-Nov-2008 16:40:16   

Hi,

Apologies if this has been asked before.

I have two collections Client and Property, linked with a many-many relationship with a PropertyClient table.

A particular Clients PropertyCollection can be accessed via

client.PropertyCollectionViaPropertyClient in code.

How can I set up a LLBLGenProDataSource to access this PropertyCollectionViaPropertyClient collection, so I can use a GridView to display property info based on the DataSource.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 12-Nov-2008 17:10:20   

Would you please explain the GUI in more details? Maybe a screenshot can be a good option here.

f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 12-Nov-2008 17:24:40   

Hi,

The GUI is just a gridview with columns that represent a collection of properties.

code as follows

<llblgenpro:LLBLGenProDataSource ID="PropertyDataSource" runat="server" DataContainerType="EntityCollection" EntityCollectionTypeName="MyDatabase.CollectionClasses.PropertyCollection, MyDatabase"> </llblgenpro:LLBLGenProDataSource>

<asp:GridView ID="PropertyGridView" runat="server" AutoGenerateColumns="False" 
    DataKeyNames="PropertyId" DataSourceID="PropertyDataSource">
    <Columns>
                               .
                               .
                               .
    </Columns>
</asp:GridView>

The problem is that I cannot just add a SelectParmeter to filter the PropertyCollection by ClientID, because its a many-many relationship as described in the original post.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 12-Nov-2008 17:40:02   

The LLBLGenProDataSource have 2 properties (FilterToUse & RelationsToUSe) which you can set at code behind.

f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 13-Nov-2008 10:01:36   

Hi,

Thanks for your reply.

Can you possibly give me an example of using the RelationsToUse property of the LLBLGenProDataSource to filter a m:n based collection?

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 13-Nov-2008 10:55:09   

For your Propert Client scenario, I guess you want to produce something like the following:

SELECT * FROM Property p
INNER JOIN ClientProperty cp ON p.Id = cp.PropertyId
WHERE cp.ClientId = xyz

Then you should have something like the following:

llblgenDS.FilterToUse = new PredicateExpression(ClientPropertyFields.ClientId == xyz);

llblgenDS.RelationstoUse = new RelationCollection();
llblgenDS.RelationstoUse.Add(PropertyEntity.Relations.ClientProperty);
f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 13-Nov-2008 11:25:46   

Many thanks,

That worked a treat.