Related entity not set in derived collection

Posts   
 
    
raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 16-Aug-2012 17:27:32   

Problem description I try to get a collection with a prefetch path, but the related entity is only set in some of the collection's elements. It only happens when Target per entity hierarchy is used and a field of each derived entity (ex. int) is mapped to the same field in the database. Maybe is this mapping not allowed?

Llblgen Pro v.3.5 August 8th, 2012

Example: - Two entities DocumentEntity & FolderEntity - Two derived entities DocEventEntity & FolderEventEntity (basetype: BaseEventEntity, abstract). Target per entity hierarchy.

  • DocEventEntity has a field IdDocument, mapped to the IdEntity field in the database. It is a FK to a DocumentEntity (navigator: Document)
  • FolderEventEntity has a field IdFolder, mapped to the same IdEntity field in the database. It is a FK to a FolderEntity (navigator: Folder)
  • BaseEventEntity has no field mapped to IdEntity

Now, I try...

PrefetchPath prefetchPath = new PrefetchPath(EntityType.FolderEventEntity);
prefetchPath.Add(FolderEventEntity.PrefetchPathFolder);
FolderEventCollection collection = new FolderEventCollection();
collection.GetMulti(null, prefetchPath);
FolderEventEntity ev = collection[0];
string folderName = ev.Folder.Nombre; // Folder is null!!!

... but the .Folder is only set in the last event with that folder (ex. event1, event2 & event3 point to folder1, then only event3.Folder is set)

Thanks in advance,

Jose

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 16-Aug-2012 20:20:03   
  • DocEventEntity has a field IdDocument, mapped to the IdEntity field in the database. It is a FK to a DocumentEntity (navigator: Document)
  • FolderEventEntity has a field IdFolder, mapped to the same IdEntity field in the database. It is a FK to a FolderEntity (navigator: Folder)

In which table does the IdEntity exist? How come same field has 2 Fks, pointing to 2 different tables?

raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 17-Aug-2012 09:16:42   
CREATE TABLE [WF].[BaseEvent] 
(
    [IdEvento] [int] IDENTITY (1,1) NOT NULL, -- PK field
    [AsociadoA] [char] (3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, -- Discriminator field (DOC/FOL)
    [IdEntity] [int] NOT NULL -- FK field (points to document.IdDocument or folder.IdFolder)
) ON [PRIMARY]
GO

As it is a 'Target per entity hierarchy' it seems allowed. confused Would the VS 2010 & Llblgen projects help?

raist
User
Posts: 114
Joined: 19-Apr-2010
# Posted on: 17-Aug-2012 10:17:31   

Solved! Of course it is allowed to map two fields in two different derived entities to the same database column. The problem was with the defined cardinality (1:1 when it should be m:1). Of course with 1:1, it does not expect related entities to be repeated, therefore it only set the last one (I suppose because of performance). Once changed to m:1 it works great (as always smile )

Thanks