UnitOfWork Entity Collection

Posts   
 
    
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 12-Nov-2006 12:31:11   

Hey,

In the function:


protected void stationCollectionDataSource_PerformWork(object sender, PerformWorkEventArgs e)
{

List<UnitOfWorkElement> list = e.Uow.GetEntityElementsToInsert();
.
.
.
}

How do i add a colletion to an entity in the 'list' so that the collection is saved using the PK from the entity? The entity and the colelction are new items.

The entity has a NEWSEQUENTIALID() as the PK. In the web.config:


<add key="SqlServerDQECompatibilityLevel" value="2" />

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 12-Nov-2006 12:46:27   

Could you elaborate a bit what you mean with 'so the collection is saved using the PK of the entity' ?

Frans Bouma | Lead developer LLBLGen Pro
deathwish
User
Posts: 56
Joined: 07-Nov-2006
# Posted on: 12-Nov-2006 13:15:40   

Hi,

Sorry bout that.

What i meant was the FK in the entity collection is set to the PK of the entity being inserted.

When i go:


e.Uow.AddCollectionForSave(SiteStationCollection, false);

The FK StationId in the SiteStationCollection is not set to the StationId of the entity after the entity is inserted.

Thanks.

Chester
Support Team
Posts: 223
Joined: 15-Jul-2005
# Posted on: 12-Nov-2006 19:10:03   

deathwish wrote:

Hi,

Sorry bout that.

What i meant was the FK in the entity collection is set to the PK of the entity being inserted.

When i go:


e.Uow.AddCollectionForSave(SiteStationCollection, false);

The FK StationId in the SiteStationCollection is not set to the StationId of the entity after the entity is inserted.

Thanks.

If you do a recursive save, the entities will be synchronized.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 12-Nov-2006 19:30:25   

Also, just add the entities to the parent entity's collection instead. (thus e.g. orders, add them to customer.Orders, using AddRange(theOrdersCollection), then simply save customer.

Frans Bouma | Lead developer LLBLGen Pro