Question about IsAutoCreated="true" on foreign key fields.

Posts   
 
    
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 21-Nov-2023 16:53:26   

LLBLGen Designer Version 5.6.1 Database first development Adapter

I was wondering how LLBLGen decides whether to mark some entity fields that correspond to foreign key fields in the database as: IsAutoCreated="true".

      <EntityDefinition Name="Account" ObjectID="ef7922fe-0767-4123-8234-785a1eab9c63">
        <Fields>
          <Field Name="AccountId" Type="int" IsReadOnly="true" IsPrimaryKey="true" FieldIndex="0" />
          <Field Name="AccountNumber" Type="string" MaxLength="35" FieldIndex="5" />
          <Field Name="AccountNumberSuffix" Type="string" MaxLength="3" FieldIndex="6" />
          <Field Name="BillValidationId" Type="int" IsAutoCreated="true" FieldIndex="3" />
          <Field Name="CategoryId" Type="int" IsAutoCreated="true" FieldIndex="1" />
          <Field Name="FundId" Type="int" IsAutoCreated="true" FieldIndex="2" />
          <Field Name="IsDuc" Type="bool" FieldIndex="11" />

I noticed some entities use IsAutoCreated="true" on the foreign key fields and others don't. I think the pattern is that older tables and entities in the project have IsAutoCreated="true" (which were probably made using LLBLGen version 2.x) while newer tables and entities that were added to the project don't.

According to the documentation: https://www.llblgen.com/Documentation/5.4/ReferenceManuals/Designer/html/B9EFCC19.htm

Gets a value indicating whether this instance is auto created fk field. Auto-created FK fields are fields which are auto-created when a relationship was created and will be removed if the relationship will removed.

I tried removing a relationship and it DID delete the entity field that was a foreign key. I don't want that behavior. So, I'd like to remove the IsAutoCreated="true". I don't see a way to do it in the LLBLGen designer. So, I was thinking about just opening the LLBLGen project file in a text editor and removing it manually.

Walaa avatar
Walaa
Support Team
Posts: 14982
Joined: 21-Aug-2005
# Posted on: 22-Nov-2023 03:46:25   

Did you try to remove the entity and re-map it back?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39747
Joined: 17-Aug-2003
# Posted on: 22-Nov-2023 09:21:30   

AutoCreated is a flag to signal the designer that the FK field was created when the relationship was created, so when the relationship is removed, the fk field is too (as it wasn't part of the entity).

Database first normally don't result in having these flags set because the fields are either there in the table and you can create the relationship, or they're not and you then can't create the relationship.

So you either are working with a model where these were created by switching to model first or indeed from a converted project (as 2.6 didn't have this info in the project).

If you don't want this behavior (removing fk field when relationship is removed), open the project in notepad and remove the xml attribute using a global search/replace.

Frans Bouma | Lead developer LLBLGen Pro
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 22-Nov-2023 17:36:33   

We never did "model first" development. So, I guess they were somehow added when converting from LLBLGen version 2.6. Thanks for the explanation. I'll just remove the IsAutoCreated="true" attribute from the project using Notepad. Thanks!