Model first SQL generation question

Posts   
 
    
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 23-Dec-2013 11:03:19   

Hello,

I created a model first project but i have a question about SQL generation.

Here is the llblgen example

BaseDomain PKID -> Guid -> PK Deleted -> Bool CreatedOn -> DateTime CreatedBy -> Guid (references to user.PKID) ModifiedOn -> DateTime ModifiedBy -> Guid (references to user.PKID) DeletedOn -> DateTime DeletedBy -> Guid (references to user.PKID)

User -> subtype of Basedomain Firstname string Lastname string

Role -> subtype of Basedomain Description string

UserRoles -> subtype of Basedomain RoleFKId -> Guid (references to Role.PKID) UserFKId -> Guid (references to user.PKID)

If we look to the entity Role there is only 1 field (in black) and 8 fields in gray (from Basedomain)

Great so far. smile

But what i espect that is that the table role in the database has 9 fields instead of 1.

In Codefirst generation this is normal behavoir, but can this be done with LLBLgen ? disappointed

Is there a demo llblgenproj file i can learn from ?

thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 23-Dec-2013 13:23:25   

this depends on the inheritance type. If you pick target per entity, each entity gets its own table, which would create a role table of 1 field and if you pick Target per entity hierarchy it would result in a table of 9 fields and the requirement of a discriminator field.

I guess you chose target per entity, which would result in a table of 1 field for the role (and the pk )

Frans Bouma | Lead developer LLBLGen Pro
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 25-Dec-2013 22:33:27   

Can you please take a look @ the llbgen project.

I added screenshot (with Target per entity hierarchy) to show that the table has only 1 field.

How can i add the missing fields from the basedomain.

thanks.

Attachments
Filename File size Added on Approval
modelfist.png 110,407 25-Dec-2013 22:34.24 Approved
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 25-Dec-2013 22:35:32   

In attachment i have my llblgen project. (Model first)

Attachments
Filename File size Added on Approval
ModelFirst.llblgenproj 14,063 25-Dec-2013 22:36.04 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Dec-2013 06:17:48   

Hi Kris,

First you created the entities as 'Target per Entity'. Then when you convert them to 'Target per Entity Hierarchy' you didn't remap the entities to the BaseDomain table. This is shown in the error list.

Also, you didn't specify a valid discriminator field and values. The default field used was Pkid, however this is not a good choice for discriminator value. I added a new one and assigned int values to the entities (1,2,3,4...). You should evaluate this a modify it as your needs.

I'm attaching the fixed project. Hope that helps.

Attachments
Filename File size Added on Approval
ModelFirst.llblgenproj 14,875 26-Dec-2013 06:18.07 Approved
David Elizondo | LLBLGen Support Team
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 26-Dec-2013 10:40:45   

Thanks for changing the Discriminator settings.

But my modelview is OK, but my tables are not

I need to have 3 tables instead of 1.

User, Roles and UserRoles.

The fields in the baseDomain are not in every table.

(In your adjusted project there is only 1 table with all fields in it.)

Is this still possible ?

Remark:

Every domain is a different table, with included fields from the basedomain.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 27-Dec-2013 03:23:39   

What you describe is not possible. You have to choose between 'Target per Entity' and 'Target per Entity Hierarchy'.

In 'Target per Entity' you have one table for supertype and for each subtype, but the common columns are in the supertype (the domain table), and the subtype tables have the specific columns.

In 'Target per Entity Hierarchy' you get only one table with all possible fields, then the subtypes are defined logically using discriminator values.

What you are describing is not possible, mainly because an entity field must be mapped to ONE column, while in your scenario you will end with two possible mappings. For instance you will get CreatedBy column on Domain and Role tables, To what column would you map the Role entity field? That is ambiguous.

For more info read Entity Inheritance.

David Elizondo | LLBLGen Support Team
Kris Nobels avatar
Posts: 118
Joined: 02-Apr-2008
# Posted on: 29-Dec-2013 12:35:22   

OK Thanks for the feedback simple_smile