Search code examples
c#linqlinq-to-sqldata-annotationsbuddy-class

Add LINQ Auto-Generated Value Marker [Column(IsDbGenerated=true)] in Buddy Class


is it possible to decorate a field of a LINQ generated class with [Column(IsDbGenerated=true)] using a buddy class (which is linked to the LINQ class via [MetadataType(typeof(BuddyMetadata))]) ?

My goal is to be able to clear and repopulate the LINQ ORM designer without having to set the "Auto Generate Value" property manually every time to re-establish the fact that certain columns are autogenerated.

Thanks!


Solution

  • LINQ to SQL does not recognize buddy classes.

    You can't just add the attribute to the partial either as the property is already defined in the other partial (this is what buddy classes were invented to solve).

    One option would be to use my T4 template for VS that replicates the code-generation functionality of LINQ to SQL (I used to work on the product team) and you could put some logic in there to detect your auto-generated columns and emit the right attribute every time.

    http://l2st4.codeplex.com