- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Generated multiple relations with the same name
Joined: 15-Nov-2005
Using LLBLGen Pro Version 2.6 Final (April 15th, 2009) Using Template: Adapter Target Platform: .NET 2.0
I have a table in our database called 'Parcel'. It actually holds 'Parcel' and 'PersonalProperty' records. In retrospect, we should've really called the table 'Property', but that was a mistake made 14 years ago.
I had used TargetPerEntityHierarchy to generate 3 Entity classes of this table: 1. PropertyEntity - the parent class, discriminator field value = some bogus value, we never add PropertyEntities to the database, we create their descendents instead. 2. ParcelEntity - descends from PropertyEntity, discriminator field value = 1 3. PersonalPropertyEntity - descends from PropertyEntity, discriminator field value = 0
There are three tables associated with the 'Parcel' table: DocumentHistory Application TractParcelMap
Originally LLBLGen made relations between: - PropertyEntity and DocumentHistoryEntity - PropertyEntity and ApplicationEntity - PropertyEntity and TractParcelMapEntity
But since these are only used by ParcelEntity, I tried changing stuff so the relationships are made with the ParcelEntity instead of the PropertyEntity. I "hid" those PropertyEntity relations and made new relations for the ParcelEntity instead.
But when I generated the code and compiled it I got errors for two of the relations:
The type 'GCS.Data.RelationClasses.ParcelRelations' already contains a definition for 'ApplicationEntityUsingParcelId'
The type 'GCS.Data.RelationClasses.ParcelRelations' already contains a definition for 'TractParcelMapEntityUsingParcelId'
How do I prevent these duplicates from getting generated?
Here are snippets from the new ParcelRelations.cs showing the duplicates:
/// <summary>Returns a new IEntityRelation object, between ParcelEntity and ApplicationEntity over the 1:n relation they have, using the relation between the fields:
/// Parcel.PropertyId - Application.ParcelId
/// </summary>
public override IEntityRelation ApplicationEntityUsingParcelId
{
get
{
IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany, "" , true);
relation.AddEntityFieldPair(ParcelFields.PropertyId, ApplicationFields.ParcelId);
relation.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("ParcelEntity", true);
relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("ApplicationEntity", false);
return relation;
}
}
/// <summary>Returns a new IEntityRelation object, between ParcelEntity and ApplicationEntity over the 1:n relation they have, using the relation between the fields:
/// Parcel.PropertyId - Application.ParcelId
/// </summary>
public virtual IEntityRelation ApplicationEntityUsingParcelId
{
get
{
IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany, "Application" , true);
relation.AddEntityFieldPair(ParcelFields.PropertyId, ApplicationFields.ParcelId);
relation.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("ParcelEntity", true);
relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("ApplicationEntity", false);
return relation;
}
}
/// <summary>Returns a new IEntityRelation object, between ParcelEntity and TractParcelMapEntity over the 1:n relation they have, using the relation between the fields:
/// Parcel.PropertyId - TractParcelMap.ParcelId
/// </summary>
public virtual IEntityRelation TractParcelMapEntityUsingParcelId
{
get
{
IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany, "TractParcelMap" , true);
relation.AddEntityFieldPair(ParcelFields.PropertyId, TractParcelMapFields.ParcelId);
relation.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("ParcelEntity", true);
relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("TractParcelMapEntity", false);
return relation;
}
}
/// <summary>Returns a new IEntityRelation object, between ParcelEntity and TractParcelMapEntity over the 1:n relation they have, using the relation between the fields:
/// Parcel.PropertyId - TractParcelMap.ParcelId
/// </summary>
public override IEntityRelation TractParcelMapEntityUsingParcelId
{
get
{
IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.OneToMany, "" , true);
relation.AddEntityFieldPair(ParcelFields.PropertyId, TractParcelMapFields.ParcelId);
relation.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("ParcelEntity", true);
relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("TractParcelMapEntity", false);
return relation;
}
}
I noticed the extra one it generated (the one that didn't exist before I made the changes) has a blank name in the EntityRelation constructor.
I noticed not all the relations were moved from Property to Parcel. Here is PropertyRelations.cs before the changes
/// <summary>Gets all relations of the PropertyEntity as a list of IEntityRelation objects.</summary>
/// <returns>a list of IEntityRelation objects</returns>
public virtual List<IEntityRelation> GetAllRelations()
{
List<IEntityRelation> toReturn = new List<IEntityRelation>();
toReturn.Add(this.ApplicationEntityUsingParcelId);
toReturn.Add(this.AssessmentEntityUsingPropertyId);
toReturn.Add(this.DocumentHistoryEntityUsingParcelId);
toReturn.Add(this.OwnershipEntityUsingParcelId);
toReturn.Add(this.ParcelAddressMapEntityUsingParcelId);
toReturn.Add(this.ParcelBankNumberMapEntityUsingParcelId);
toReturn.Add(this.ParcelDistrictMapEntityUsingParcelId);
toReturn.Add(this.PropertyAddressEntityUsingParcelId);
toReturn.Add(this.TractParcelMapEntityUsingParcelId);
toReturn.Add(this.MunicipalityEntityUsingMunicipalityId);
return toReturn;
}
Here it is after, you'll notice DocumentHistory relation is gone, but the others stayed:
/// <summary>Gets all relations of the PropertyEntity as a list of IEntityRelation objects.</summary>
/// <returns>a list of IEntityRelation objects</returns>
public virtual List<IEntityRelation> GetAllRelations()
{
List<IEntityRelation> toReturn = new List<IEntityRelation>();
toReturn.Add(this.ApplicationEntityUsingParcelId);
toReturn.Add(this.AssessmentEntityUsingPropertyId);
toReturn.Add(this.OwnershipEntityUsingParcelId);
toReturn.Add(this.ParcelAddressMapEntityUsingParcelId);
toReturn.Add(this.ParcelBankNumberMapEntityUsingParcelId);
toReturn.Add(this.ParcelDistrictMapEntityUsingParcelId);
toReturn.Add(this.PropertyAddressEntityUsingParcelId);
toReturn.Add(this.TractParcelMapEntityUsingParcelId);
toReturn.Add(this.MunicipalityEntityUsingMunicipalityId);
return toReturn;
}
Here is how ParcelRelations.cs changed: Before:
/// <summary>Gets all relations of the ParcelEntity as a list of IEntityRelation objects</summary>
/// <returns>a list of IEntityRelation objects</returns>
public override List<IEntityRelation> GetAllRelations()
{
List<IEntityRelation> toReturn = base.GetAllRelations();
toReturn.Add(this.LotTypeEntityUsingLotTypeId);
toReturn.Add(this.PlatEntityUsingPlatId);
return toReturn;
}
After:
/// <summary>Gets all relations of the ParcelEntity as a list of IEntityRelation objects.</summary>
/// <returns>a list of IEntityRelation objects</returns>
public override List<IEntityRelation> GetAllRelations()
{
List<IEntityRelation> toReturn = base.GetAllRelations();
toReturn.Add(this.ApplicationEntityUsingParcelId);
toReturn.Add(this.DocumentHistoryEntityUsingParcelId);
toReturn.Add(this.TractParcelMapEntityUsingParcelId);
toReturn.Add(this.LotTypeEntityUsingLotTypeId);
toReturn.Add(this.PlatEntityUsingPlatId);
return toReturn;
}
I don't know if it matters or not, I have only recently changed stuff in LLBLGen to generate the three separate classes off of the Parcel table. Before, we just let LLBLGen generate one single entity class that represented all the fields in the table.
Thanks for any help.
So you setup a TPEH, then hide a relation on the parent. Then you add such relation (manual) on the sub-entity. Then you regenerated and duplicate relations appear.
I can't reproduce it.
- Are you hiding the relation on both sides?
- Your LLBLGen version is a little bit old. Please update to the latest one (reinstall), then regenerate the code.
- If you still don't get this working, please attach you .lgp project so we can take a look at it. To do so, please open a HelpDesk forum (private).
Joined: 15-Nov-2005
daelmo wrote:
So you setup a TPEH, then hide a relation on the parent. Then you add such relation (manual) on the sub-entity. Then you regenerated and duplicate relations appear.
Yes. I wonder why it happened for two of the relations (Application, TractParcelMap) but not the third (DocumentHistory).
daelmo wrote:
- Are you hiding the relation on both sides?
Yes.
daelmo wrote:
- Your LLBLGen version is a little bit old. Please update to the latest one (reinstall), then regenerate the code.
That may take a while. I only seem to have a login for when we bought version 1.x and when I log in all I get is the option to download versions of 1.x. I'll have to find our login from when we purchased (upgraded to?) version 2.x.
daelmo wrote:
- If you still don't get this working, please attach you .lgp project so we can take a look at it. To do so, please open a HelpDesk forum (private).
I hope you don't mind, but I think I'm just going to give you the .lgp project right away instead of waiting to upgrade. So look for the post on your HelpDesk forum.
Joined: 15-Nov-2005
clint wrote:
daelmo wrote:
- Are you hiding the relation on both sides?
Yes.
Oops. I guess I was wrong. When I went to edit the Properties entity, I noticed the relations for TractParcelMap and Application actually were not grayed out. So I right clicked on them and clicked 'Toggle Hide Flag on Selected Relation(s) both sides()'. Now the code is generating properly.
Thanks.