Omitting DataMember on reverse navigation properties
Posted: Thu 25 Apr 2013 06:54
We have a change request for the DbContext template that may put us in the minority, but we would like to have the option of omitting the DataMember attribute on reverse navigation properties when using the WCF Data Contract option in the DbContext template, but we do want the attribute on regular properties, and of course on regular entity fields.
As an example, if there's an entity Order and another entity OrderLine, and OrderLine has a foreign key to Order, we want the Order property on the OrderLine entity to have DataMember, but the OrderLines property on the Order entity should not.
We have two reasons for this:
1. We're using the entity classes as DTO classes as well as in our internal code, and although we do use the navigation properties internally, we have no desire to expose the reverse navigation properties to anyone else.
2. We experienced some pretty severe issues when trying to import WSDLs using the data contract hierarchies with reverse navigation properties into SoapUI, presumably owing to the complexity of the hierarchy or possibly something to do with circular references. This may just be a bug with that program, but we can't be certain that the same problem won't affect other programs -- particularly other Java-based programs.
We've implemented this as a one-liner in our modified version of the DbContext template, although I'm sure that if you were to implement this it would have to be as a configurable option.
As an example, if there's an entity Order and another entity OrderLine, and OrderLine has a foreign key to Order, we want the Order property on the OrderLine entity to have DataMember, but the OrderLines property on the Order entity should not.
We have two reasons for this:
1. We're using the entity classes as DTO classes as well as in our internal code, and although we do use the navigation properties internally, we have no desire to expose the reverse navigation properties to anyone else.
2. We experienced some pretty severe issues when trying to import WSDLs using the data contract hierarchies with reverse navigation properties into SoapUI, presumably owing to the complexity of the hierarchy or possibly something to do with circular references. This may just be a bug with that program, but we can't be certain that the same problem won't affect other programs -- particularly other Java-based programs.
We've implemented this as a one-liner in our modified version of the DbContext template, although I'm sure that if you were to implement this it would have to be as a configurable option.