Using Bind on an nested Entity

Posts   
 
    
f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 20-Nov-2008 17:41:13   

I have two objects with a 1-1 relationship

ie, a House object that has a GardenId property that references a Garden object and a Number property that contains the street number of the house

so i could write code as follows

HouseEntity h = new HouseEntity(21); h.Number = 13; h.Garden.Width = 100; h.Save(true);

in this case the House's street number would be set to 13 and the associated Garden object, Width property would be set to 100,

Because the recurse parameter of the House's Save() method has been set to true the Garden's Width property would also be properly persisted

My question is if I want to bind this Garden.Width property to a TextBox in a FormView it would be something like this:

<asp:FormView ID="HouseDetailsFormView" runat="server" DataKeyNames="HouseId" DataSourceID="HouseDetailsDataSource"> <EditItemTemplate>

   <asp:TextBox ID="HouseNumber" runat="server" 
           Text='<%# Bind("Number") %>' />

    <br/>

    <asp:TextBox ID="GardenWidth" runat="server" 
           Text='<%# Bind("Garden.Width") %>' />

</EditItemTemplate>

</asp:FormView>

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

However

When I update this FormView, the House's Number property is persisted, but the Garden.Width property is not.

I need to figure out how to persist recursively using DataBinding.

Thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 20-Nov-2008 21:14:29   

Does your MyDatabase.CollectionClasses.HouseCollection contain House entities with pre-fetched Garden entities ? ie are you sure that the Garden Entity is present to bind to ?

f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 21-Nov-2008 09:53:56   

Well the following code will work

HouseEntity h = new HouseEntity(21); h.Number = 13; h.Garden.Width = 100; h.Save(true);

So I presume there is a pre-fetched Garden entity,

In other words the HouseEntity with HouseID = 21 exists and does have a corresponding Garden entity, whose width=100 property has now been persisted

Or have I misunderstood your question?

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

I think, this happens because saving the entity won't be done recursively.

So I suggest you set LivePersistence = false, and handle the events manually. This will allow you to handle the PerformWork event, and save the home entity recursively.

f88
User
Posts: 7
Joined: 12-Nov-2008
# Posted on: 21-Nov-2008 10:42:35   

Thanks for that,

Was hoping I wouldn't have to do that rage