Possible T4 template enhancement?

Nov 4, 2011 at 11:56 AM

Does anyone agree that in a database first scenario, it would be nice for the default T4 templates shipped to ensure that when a navigation property is changed on one type, that the type at the other end is updated automatically?

I.e.

I have two types: Client and Group

Client has a collection of Groups

Group has a single Client

When I execute the following code it would be nice client.Groups now contains group:

private void AssociateGroupWithClient(Group group, Client client)
{
    group.Client = client;
}

Rather then having to do the following:
private void AssociateGroupWithClient(Group group, Client client)
{
    group.Client = client;
    client.Groups.Add(group);
}

Coordinator
Nov 4, 2011 at 3:55 PM

I'm puzzled, Paul, because Entity Framework should be setting up the reverse association for you automatically  -  without the need to explicitly code it. In other words, specifying the Client property on a Group, should automatically result in the Group appearing within the Client.Groups collection.  If it isn't then this suggests that the entity model isn't picking up the association from the database properly  -  I assume that the association is via a foreign key, yes? 

Nov 4, 2011 at 4:26 PM

I'll dig a bit deeper on Monday, and let you know what I find.

Nov 10, 2011 at 4:15 PM

Don't know what was going on, because it is working as expected now, with the Entity Framework setting up the reverse association.