Following goose's post these are the final list of steps:
**1. **Indicate to LLBLGenDataSource that prefetch Address Entity.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IPrefetchPath2 path = new PrefetchPath2((int)EntityType.EmployeeEntity);
path.Add(EmployeeEntity.PrefetchPathAddress);
// here use your LLBLGenDataSource object name
this._employeeDS.PrefetchPathToUse = path;
}
}
2. Create Entity Custom Properties for ZIP and City fields on EmployeeEntity.cs USER_REGION:
// __LLBLGENPRO_USER_CODE_REGION_START CustomEntityCode
public virtual System.String City
{
get
{
if (this.Address != null)
{
return this.Address.City;
}
else
{
return (System.String)TypeDefaultValue.GetDefaultValue(typeof(System.String));
}
}
set
{
if (this.Address != null)
{
this.Address.City = value;
}
}
}
///...
///... same for ZIP
// __LLBLGENPRO_USER_CODE_REGION_END
3. Delete AddressId column from your GridView declarative code and add these ones: (note that here your are binding your already created custom property City and ZIP.
<asp:TemplateField HeaderText="City" ItemStyle-CssClass="ColumnContent" ItemStyle-Wrap="false" HeaderStyle-CssClass="tableheaders" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Wrap="false">
<EditItemTemplate>
<asp:TextBox
ID="CityEdit"
runat="server"
Text='<%# Bind("City") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="City" runat="server" Text='<%# Bind("City") %>'/>
</ItemTemplate>
</asp:TemplateField>
///...
///... same for ZIP
**4. **As LLBLGenProDataSource won't save recursively the changes made in AddressEntity, you need to:
**4.1.** Set **_yourLLBLGenProDataSource.LivePersistence = false**;
**4.2.** Add a handler for **_yourLLBLGenProDataSource.PerformSelect
**
protected void _yourLLBLGenProDataSource_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs2 e)
{
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(e.ContainedCollection, e.Filter, e.MaxNumberOfItemsToReturn, e.Sorter, e.PrefetchPath, e.PageNumber, e.PageSize);
}
}
**4.2.** Add a handler for** _yourLLBLGenProDataSource.PerformWork**
protected void ldsProducts_PerformWork(object sender, PerformWorkEventArgs e)
{
// needed for know the product entities that will be upated
e.Uow.ConstructSaveProcessQueues();
System.Collections.Generic.List<UnitOfWorkElement2> updateEntityList = e.Uow.GetEntityElementsToUpdate();
// for each product entity add its related supplier to the save queue
foreach (UnitOfWorkElement2 ouwe in updateEntityList)
{
if (((EmployeeEntity)ouwe.Entity).Address != null && ((EmployeeEntity)ouwe.Entity).Address.IsDirty)
{
e.Uow.AddForSave(((EmployeeEntity)ouwe.Entity).Address);
}
}
// finally.. save uow (containing EnpolyeeEntity and its related AddressEntity
using (DataAccessAdapter adapter = new DataAccessAdapter))
{
e.Uow.Commit(adapter, true);
}
}
This would seems cumbersome, but once you make it, it would be a piece of cake in future times.
Please let us know if everything is clear and helpul
Regards.