Question

I have a T4 template that outputs some code for each table in my model.

I need it to be able to distinguish between a property of a class that is a normal "1 * many" collection property, and one that is a "1 * many" but hiding a collapsed many to many link.

For example, if I have "Table1", "Table2", "Table3", "Table4" and "Table5". "Table1" has a 1 * many to "Table2". "Table3" has a many to many to "Table5" using "Table4" as the link table.

In entity framework, "Table4" would not be shown, and you would navigate the links as follows:

"Table3" -> "Table5CollectionProperty" -> "Table5"

"Table5" -> "Table3CollectionProperty" -> "Table3"

So what I want to know is, if I am using a T4 template, is there a way to find out if the property "Table5CollectionProperty" is in fact a property hiding a many to many link?

EDIT

Or at the very least, is there a way to find this out using the context in c# code?

Was it helpful?

Solution

Ok, after doing a bit of digging into MSDN, I believe I have found a way to find this out. In the T4 template I can access properties as follows:

if (navProperty.FromEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many &&
    navProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
    // deal with many to many link collections here...
}

Posting it here in case anyone else has a need for this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top