entity inheritance and CRUD operations

Posts   
 
    
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 20-Dec-2007 20:30:45   

llbl 2.0 orm 2.0.7.810 adapter

domain: BatchEntity 1:N ReportEntity ReportEntity 1:1 ReportDataEntity (heirachy)

batch is a logical grouping of reports. report is a single report related to a specific batch reportdata is the actual report as a byte array. this way i don't need to fetch the bytes with each call.

scenario: within the database exists a record for batch and associated report records. no records exist for reportdata at this point. (Only a request for the reports is saved, the actually report has not be generated.)

does this code work?

IPrefetchPath2 prefetch = new PrefetchPath2((int)EntityType.BatchEntity);
prefetch.Add(BatchEntity.PrefetchPathReport);

ReportBatchEntity batch = new ReportBatchEntity(1);
adapter.FetchEntity(batch, null, prefetch);

foreach(ReportDataEntity dataOfReport in batch.Reports)
{
         dataOfReport.Data = GenerateReportAsByteArray();
         dataOfReport.Status = StatusEnum.Completed;
}
uow.AddForSave(batch);
uow.commit(adapter, true); **

Note I prefetch ReportEntities but a enumerate over ReportDATAEntities. Data is a property of ReportData entity. Status is a property of Report entity. ** expected psuedo sql

begin tran
insert into report_data_tbl (id, data) values (1, byte[])
update report_tbl set status = 3 where id = 1
commit tran

are these assumptions correct?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-Dec-2007 11:21:08   

It seems correct, but if you have a report entity createde without it data part, you won't add the data entity later on, as entities in a Hierarchy can't change their type. Rather you would have to delete the Report entity and re Insert the Data entity.