Error "Already contains a definition...."

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 02-Mar-2007 18:13:22   

Newest version as of last week. VS.NET 2005, Self-serving

I have a sub-type "PersonName" which has a relation to "Person"

When I generate the code, I get:

The type 'ERMS.Apps.TaskApprovals.DAL.RelationClasses.PersonNameRelations' already contains a definition for 'PersonEntityUsingPersonId'

The error is on the virtual method. I think it's trying to override PersonEntityUsingPersonId in the same class which I don't think you can do simple_smile

The relationship was made manually in the GUI. If removed, this code block works fine, but then I get code generated with a GetMultiManyToOne, which doesn't exist in the sub-type "PersonName".


        /// <summary>Returns a new IEntityRelation object, between PersonNameEntity and PersonEntity over the m:1 relation they have, using the relation between the fields:
        /// PersonName.PersonId - Person.PersonSid
        /// </summary>
        public override IEntityRelation PersonEntityUsingPersonId
        {
            get
            {
                IEntityRelation relation = base.PersonEntityUsingPersonId;
                relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("PersonNameEntity", true);
                return relation;
            }
        }
    
        /// <summary>Returns a new IEntityRelation object, between PersonNameEntity and PersonEntity over the m:1 relation they have, using the relation between the fields:
        /// PersonName.PersonId - Person.PersonSid
        /// </summary>
        public virtual IEntityRelation PersonEntityUsingPersonId
        {
            get
            {

                IEntityRelation relation = new EntityRelation(SD.LLBLGen.Pro.ORMSupportClasses.RelationType.ManyToOne);
                relation.StartEntityIsPkSide = false;
                relation.AddEntityFieldPair(EntityFieldFactory.Create(PersonFieldIndex.PersonSid), EntityFieldFactory.Create(PersonNameFieldIndex.PersonId));
                relation.InheritanceInfoPkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("PersonEntity", false);
                relation.InheritanceInfoFkSideEntity = InheritanceInfoProviderSingleton.GetInstance().GetInheritanceInfo("PersonNameEntity", true);
                return relation;
            }
        }


Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 02-Mar-2007 18:40:51   

You inherit a relation from a supertype which has the same field mapped onto it, I think that's it, could you check that for me please?

Frans Bouma | Lead developer LLBLGen Pro
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 02-Mar-2007 18:48:52   

Ahhh. that helps.

Yes. PersonName is a Sub-Type of "Name" (abstract) Person has a relation to PersonName (manually made) and Name has one with Person (auto made).

I removed any relationship that Name had to Person and added the relationship manually between Person and PersonName. It now works.

So is the rule: Do all your relations between the sub-types, not super-types?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 02-Mar-2007 20:32:15   

You don't have to remove relations, you can RENAME the field mapped onto the relation, so the names don't clash simple_smile

Frans Bouma | Lead developer LLBLGen Pro