Changing Related Entity Names

Posts   
 
    
ElQueso avatar
ElQueso
User
Posts: 27
Joined: 08-Oct-2005
# Posted on: 29-Mar-2008 04:17:25   

First, I am using version 2.5 Final (December 5th, 2007) SQL Server 2005.

This is related to how to name related entities in another entity, and how to access related fields on these related entities and a problem I ran into with inherited entities in this scenario.

Take the following table structure example:

TraceSets ( TraceSetID uniqueidentifier CONSTRAINT PK_Tracesets PRIMARY KEY .... )

TraceTypes ( TraceTypeID int identifier CONSTRAINT PK_TraceTypes PRIMARY KEY, TraceType nvarchar(50) NOT NULL )

Traces ( TraceID uniqueidentifier CONSTRAINT PK_Traces PRIMARY KEY, TraceSetID uniqueidentifier NOT NULL CONSTRAINT FK_Traces1 REFERENCES TraceSets(TraceSetID), TraceTypeID int NOT NULL CONSTRAINT FK_Traces2 REFERENCES TraceTypes(TraceTypeID) ... )

NumericTraces ( TraceID uniqueidentifier CONSTRAINT FK_NumericTraces1 REFERENCES Traces(TraceID) CONSTRAINT PK_NumericTraces PRIMARY KEY, ... )

DateTimeTraces ( TraceID uniqueidentifier CONSTRAINT FK_DateTimeTraces1 REFERENCES Traces(TraceID) CONSTRAINT PK_DateTimeTraces PRIMARY KEY, ... )

So I have a TraceSet, which contains a collection of Traces. NumericTraces and DateTimeTraces are a 1 to 1 relationship to Traces, so Traces is a master entity, NumericTraces and DateTimeTraces being subtypes in Gen Pro.

Traces also has a TraceType.

My table names in the database are all plural. I rename my entities to singular forms of the table names.

If I want to create a list of Traces, I would normally want to display the TraceType string with the other trace fields (not shown in the table). In Gen Pro I would go to the Trace entity in the editor and create a field in Fields On Related Fields, which is fine. The problem is, the default name of the field would be TraceType, which also happens to be the name by default of the TraceType entity that is realted to traces, and I cannot therefore name my field TraceType.

I did not at first realize that you had a project property named FieldMappedOnOneManyToOnePatten which did this for me automatically (my partner pointed this out to me), so I have been renaming my related entities in the FieldsOnRelations tab in the designer by hand, placing the text "Entity" after them. Discovery of this property is very helpful for the future.

But the problem I ran into is related to some of the entity generated code related to the inherited traces. I used TraceTypes as an example of naming convention only. Keep in mind that I name ALL my related entity fields thus in all of entities in the designer.

Therefore, as an example, in the Traces entity I have a mapped entity relation field named TraceSetEntity which represents the parent of the Trace.

When I try to add a Trace to the Traces collection in the TraceSet entity (using traceSet.Add(trace)), the parent entity of the Trace never gets set. Here's what happens:

Traces.Add causes the following method to be called, in the NumericTraceEntity (I am dealing specifically with a NumericTrace in this instance, but it is a problem with all sub-types of Traces):

public override void SetRelatedEntity(IEntity2 relatedEntity, string fieldName) { switch(fieldName) { case "InterpolationTypeEntity": SetupSyncInterpolationTypeEntity(relatedEntity); OnRelatedEntitySet(relatedEntity, fieldName); break; case "TraceTypeEntity": SetupSyncTraceTypeEntity(relatedEntity); OnRelatedEntitySet(relatedEntity, fieldName); break; case "UnitEntity": SetupSyncUnitEntity(relatedEntity); OnRelatedEntitySet(relatedEntity, fieldName); break;

   default:
        base.SetRelatedEntity(relatedEntity, fieldName);
        break;
}

}

The problem is, the value of the "fieldName" parameter is "TraceSet" (which was the name of the field before I manually changed it) and not "TraceSetEntity" (which I changed it to). The code executes the "default" line of the switch statement, which is calling the master type's SetRelatedEntity method (i.e., in the Trace entity, not the NumericTrace subtype entity). In that method is the following:

public override void SetRelatedEntity(IEntity2 relatedEntity, string fieldName) { switch(fieldName) { case "TraceSetEntity": SetupSyncTraceSet(relatedEntity); OnRelatedEntitySet(relatedEntity, fieldName); break;

    default:
        break;
}

}

So, as you can see, the code itself is expecting the correct name - "TraceSetEntity", but in fact the value that is passed through to this method (from the subtype's method) in the fieldName parameter is "TraceSet".

I went back to the designer and for the Trace entity master type, I set the TraceSet entity's property back to being called TraceSet (from TraceSetEntity) and everything worked fine.

It's possible that this only happens when the name is manually changed after the entity is added to the project. I.e., I haven't tried setting the FieldMappedOnOneManyToOnePatten property in the project and adding it to see if there is something in the manual process that doesn't work properly.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 29-Mar-2008 07:16:31   

Hola ElQueso,

I've tested your scenario and everything works just fine to me. First of all, could you please update to the lastet build ( 28-mrt-2008 )?

David Elizondo | LLBLGen Support Team
ElQueso avatar
ElQueso
User
Posts: 27
Joined: 08-Oct-2005
# Posted on: 30-Mar-2008 17:44:14   

Thanks for your quick response on this. I have somehow managed to lose my customer code (confused ) and can't log in to the customer section of the website. I had that info in an email from when I bought my license that I have somehow managed to lose. I've sent off an email to get that little piece of information.

In the meantime, please don't close this out yet - I'll upgrade to the latest version when I get my customer code and let you know if that took care of this issue...

One update though. I did try deleting the entity in the designer and then re-adding with the propject property FieldMappedOnOneManyToOnePattern set to {$EndEntityName}Entity, just to see if having that set automatically on addition of an entity to the project made any difference and it did not. I still get that error, and only when the entity is a sub-type of another entity where I've changed that name.

Anyway, I'll post my results of redoing my data layer in when I get updated to the latest build.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 31-Mar-2008 10:16:37   

ElQueso wrote:

Thanks for your quick response on this. I have somehow managed to lose my customer code (confused ) and can't log in to the customer section of the website. I had that info in an email from when I bought my license that I have somehow managed to lose. I've sent off an email to get that little piece of information.

In the meantime, please don't close this out yet - I'll upgrade to the latest version when I get my customer code and let you know if that took care of this issue...

We've emailed you your customerid + password. If you didn't receive it, please let us know.

One update though. I did try deleting the entity in the designer and then re-adding with the propject property FieldMappedOnOneManyToOnePattern set to {$EndEntityName}Entity, just to see if having that set automatically on addition of an entity to the project made any difference and it did not. I still get that error, and only when the entity is a sub-type of another entity where I've changed that name.

Anyway, I'll post my results of redoing my data layer in when I get updated to the latest build.

As David couldn't repro your situation, we'll wait till you've upgraded to the latest build.

Frans Bouma | Lead developer LLBLGen Pro
ElQueso avatar
ElQueso
User
Posts: 27
Joined: 08-Oct-2005
# Posted on: 01-Apr-2008 02:49:54   

Thanks for helping me with my idiocy on losing my customer id flushed

I upgraded to the new version and regenerated and had the same problem.

Then, just to make sure, I deleted my exiting data layer projects and regenerated.

Still had the problem.

Let me know how I should proceed at this point. If I were to upload the generated entity code involved would it help? Or maybe need to upload all of the generated code?

In the meantime, I am going to go back and rename my related field to remove the text "Entity" which will allow me to continue for now.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Apr-2008 06:11:35   

Hi... mmmm disappointed ... at this point a tiny-repro-solution would be helpful. If you can attach it to your post (without binaries) would be great (only the LGP file and the DDL scripts with some data inserts) or email me at david.elizondo AT llblgen.com.

I've tested your scenario with the Auditing example (available at llblgen site). Using the inheritance of OrderAuditInfo -> AuditInfo and the AuditInfo's field on related entity User, then make the renaming, generation, etc, the parent AuditInfo is expecting the correct field's name, and the inherited OrderAuditInfo is passing the correct one as well.

Maybe I'm over sighting something in my test, so if you could attach/send us a tiny-repro solution, that would accelerate things wink

Cheers.

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 01-Apr-2008 10:21:12   

I have a difficult time following your scenario, ElQueso: a question I run into is: the field mapped onto related field, is that an inherited field in both subtypes? or do you define that field in both entities ?

Frans Bouma | Lead developer LLBLGen Pro
ElQueso avatar
ElQueso
User
Posts: 27
Joined: 08-Oct-2005
# Posted on: 01-Apr-2008 18:40:45   

Otis wrote:

I have a difficult time following your scenario, ElQueso: a question I run into is: the field mapped onto related field, is that an inherited field in both subtypes? or do you define that field in both entities ?

The field I'm having problems with is inherited in the subtypes.

So, I have a TraceSet, that's the parent. The TraceSet has a collection of Traces. The Trace is the master type, and the sub types are NumericTrace, StringTrace, DateTimeTrace, etc. So the foreign key to the TraceSet is actually in the Trace master type, inherited by the sub types.

So, in the designer, I have a related field in the Trace master type called TraceSet that I renamed to TraceSetEntity. The strange thing has been, when I go to the designer and look at the sub types, Fields On Relations, in the Inherited Fields On Relations, I always see what I expect. That is, the readonly grid shows me a field named TraceSetEntity as I expect.

It's when I add a NumericTrace entity to a TraceSet using traceSet.Traces.Add(numericTrace) that I have this issue and the field name parameter comes across as "TraceSet" not "TraceSetEntity".

I'm working on seeing if I can reproduce this in a small project right now. My biggest problem is that I am swamped (as I'm sure you guys are too!) and having a hard time getting to it simple_smile

ElQueso avatar
ElQueso
User
Posts: 27
Joined: 08-Oct-2005
# Posted on: 01-Apr-2008 20:27:38   

Well, I made some time and of course, ended up with the result I figured I'd probably end up with simple_smile

I created a small database of 4 tables, the ones that were involved in my issue. Of course, I had a lot of foreign keys to remove for relations to other tables not in the sample, but not the ones that were directly involved in what appeared to be the problem so that shouldn't have had any bearing on what I was trying to recreate.

I created a small Windows project to create a new TraceSet and add a NumericTrace entity to the collection of Traces on the TraceSet.

It worked fine. rage

So, I can't figure out what the problem is with my current data layer. It seems to me that it must be a situation with the Gen Pro project file itself (it has been through 3 or so different version of Gen Pro over its lifetime), maybe? Because I can delete my data layer in its entirety and recreate and have the same problem, but when I do it with a new project (albeit a very, very small representation of the true project) it goes away.

I toyed with the idea of recreating my data layer from scratch (i.e., creating a new Gen Pro designer project) but I have a lot of other things that I have to do to make that work and just don't have the time. If I knew for sure that it would make the difference I might do it, but if I redo it all and end up with the same result I'd be hurting wink

Anyway, this isn't the end of the world. I just have one entity hierarchy at this point that's causing the problem and it's the only one that's not named the same as the rest. I can live with this.

If there's something you all can suggest, or something you can look at, let me know and I will do so.