I use Linq to Sql (although this is equally applicable in Entity Framework) for my models, and I’m finding myself creating buddy classes for my models all the time. I find this time consuming and repetitive. Is there an easy way to automatically generate these buddy classes based on the models? Perhaps a visual studio macro?
An example of a buddy class that I’d like to create:
[MetadataType(typeof(PersonMetadata))]
public partial class Person
{
}
public class PersonMetadata
{
public object Id { get; set; }
public object FirstName { get; set; }
}
Thanks in advance.
I would take a look at Text Templates (tt) in Visual Studio 2010 (I believe you can use them in 2008, but there’s not as much support for them as there is in 2010).
It will allow you to write a generic template using code which you can use to generically process your LINQ to SQL types and generate the buddy classes for.