Adding Attributes to generated code

Oct 16, 2007 at 9:38 PM
Edited Oct 16, 2007 at 9:40 PM
This probably isn't directly a Repository Factory questions, but I'm hoping that some of the people using the Repository Factory code generation have run into similar situations and maybe can advise.

The Business Entities project contains the classes that are auto-generated from the database tables. However, the application that we're developing that is using those business objects is doing its communication through WCF. To expose classes and data members to WCF serialization, you need to put the [DataContract]'} and {"[DataMember] attribute on the classes and properties, respectively.

Since the Repository Factory creates partial classes, this isn't difficult to do on the class definition. For example, if the Repository Factory generated MyClass.cs:

public partial class MyClass

I can create MyClassEx.cs and add declare:

[DataContract]
public partial class MyClass

and the WCF serialization can work. Problem is, I can't figure out a way to do that for the data members, since if you try to "redeclare" the 'MyProperty' member definition in the MyClassEx.cs, you get an error message like: "The type 'MyClass' already contains a definition for 'MyProperty', which you would expect.

Of course, the easy answer is that I can just go add all of the attributes that I need into the auto-generated classes, but the obvious problem there is that then if I have to regenerate the class, I lose the attributes. I'd rather be able to keep it separate if at all possible.

Any thoughts?

Curt Berry
Austin, TX

Oct 17, 2007 at 12:11 AM

CurtCBerry wrote:
This probably isn't directly a Repository Factory questions, but I'm hoping that some of the people using the Repository Factory code generation have run into similar situations and maybe can advise.

The Business Entities project contains the classes that are auto-generated from the database tables. However, the application that we're developing that is using those business objects is doing its communication through WCF. To expose classes and data members to WCF serialization, you need to put the [DataContract]'} and {"[DataMember] attribute on the classes and properties, respectively.

... snip ...

Any thoughts?

Curt Berry
Austin, TX




My first thought is that this directly couples your data contracts to your database schema. Are you sure you want to do that? We discussed this a bit when building the package originally on the Web Service Software Factory, and came to the conclusion that your entities and contracts should be separate, with translator classes.

If you really want to do this it wouldn't be hard to modify the templates, but I wouldn't recommend it.