I have a need to manually set which part of a Parent/Child association between LinqToSql objects gets marked with the DataMember attribute. Currently it appears that the DBML designer always chooses the Child property to have the DataMember attribute and I cannot figure out how to force it the other way.
I need this to work for default serialization (DataContractSerializer). I cannot delete the Child property (this would leave only the Parent and give the Parent the DataMember attribute, which does work for me in some circumstances, but not all). I need to be able to say “for this association, the Parent needs to be the DataMember, and the Child should not be.”
Is there some way to dictate to an object which of its properties should or should not be DataMembers? The only way I can find to do this is to manually edit the .Designer file and that is obviously not a solution.
Based on the non-response here, I researched and discovered that POCO functionality with Linq to Sql is actually quite easy, and makes my issue as posted moot. With POCO classes I can define the serialization however I want and I am not limited by the DBML designer.
This blog post has the essential basics, and there is plenty of info available with an easy search for “linq2sql poco” here on SO or Google.
I also relied heavily on this blog post that ties it together with DDD Repositories.