I need to convert the following v2.6 template code to v3 template code.
//automatic relations
for (int i = 0; i < currentEntity.Relations.Count; i++)
{
bool process = false;
if (currentEntity.Relations[i].RelationType != EntityRelationType.ManyToMany)
{
process = currentEntity.Relations[i].StartEntityIsPkSide;
}
if (process) {
switch (currentEntity.Relations[i].RelationType)
{
case EntityRelationType.OneToMany:
__outputWriter.Write(" private {0}DTOCollection f{1};\r\n", currentEntity.Relations[i].RelationEndName, currentEntity.Relations[i].RelationEndName);
__outputWriter.Write(" public {0}DTOCollection {1} {{ get {{ return f{1}; }} set {{ f{1} = value; }} }}\r\n", currentEntity.Relations[i].RelationEndName, currentEntity.Relations[i].UtilizingPropertyName);
break;
case EntityRelationType.ManyToOne:
case EntityRelationType.OneToOne:
__outputWriter.Write(" private {0}DTO f{1};\r\n", currentEntity.Relations[i].RelationEndName, currentEntity.Relations[i].UtilizingPropertyName);
__outputWriter.Write(" public {0}DTO {1} {{ get {{ return f{1}; }} set {{ f{1} = value; }} }}\r\n", currentEntity.Relations[i].RelationEndName, currentEntity.Relations[i].UtilizingPropertyName);
break;
}
}
}
and this is what i have so far and i am not sure if this is right
var relationships = _executingGenerator.ProjectDefinition.GetAllRelationshipsForEntity(currentEntity, true);
foreach (var rel in relationships)
{
bool process = false;
if (relEdge.RelationshipType != EntityRelationshipType.ManyToMany)
{
if (rel is NormalRelationshipEdge)
{
NormalRelationshipEdge nEdge = (NormalRelationshipEdge)rel;
process = nEdge.StartEntityIsPkSide;
}
}
if (process)
{
if (rel is NormalRelationshipEdge)
{
NormalRelationshipEdge nEdge = (NormalRelationshipEdge)rel;
switch (nEdge.RelationshipType)
{
case EntityRelationshipType.OneToMany:
__outputWriter.Write(" private {0}DTOCollection f{1};\r\n", relEdge.EndEntityNavigator, relEdge.UniqueAssociationName);
__outputWriter.Write(" public {0}DTOCollection {1} {{ get {{ return f{1}; }} set {{ f{1} = value; }} }}\r\n", relEdge.EndEntityNavigator, relEdge.UniqueAssociationName);
break;
case EntityRelationshipType.ManyToOne:
case EntityRelationshipType.OneToOne:
__outputWriter.Write(" private {0}DTO f{1};\r\n", relEdge.EndEntityNavigator, relEdge.UniqueAssociationName);
__outputWriter.Write(" public {0}DTO {1} {{ get {{ return f{1}; }} set {{ f{1} = value; }} }}\r\n", relEdge.EndEntityNavigator, relEdge.UniqueAssociationName);
break;
}
}
}
}
The problem i am having is the StartEntityIsPKSide is always false even if the current entity is the primary key table.
For example I have two table ui_audit_sch_ltrs_hdr and ui_audit_sch_ltrs_dtl and they have one to many relationship between them. But when i call the method GetAllRelationshipsForEntity for the current entity the relations I get is reverse of what I have in the database. So if i have one-to-many relationship the normalrelationship edge RelationType property value is ManyToOne.
I am attaching the quick watch window of the relations object from visual studio. If you see in the attached image the startvertex is uiauditschltrsdtl and endvertext is uiauditschltrshdr and i think it should be the otherway.
Thanks
Sunil Gaddam