tags:

views:

162

answers:

2

I want to add browsable attribute to some properties for entities generated by LINQ to SQL.

Is it a good idea? Since these entities are auto-generated, and when I regenerate they (the attributes I have added) might be overwritten.

A: 

You cannot add additional attributes to the properties in another partial class file because you would be defining the property more than once. This is one reason, among others, that we created our own code generator that generates L2S entity classes the way we want them.

Our code generator also generates a second set of 'application' entities that are much more lightweight than the L2S entities and used at the application level. They contain no L2S plumbing, but do contain other characteristics that the application level finds useful.

Randy Minder
This isn't correct, you can do this using the MetadataType attribute: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.metadatatypeattribute.aspx See here for a full tutorial example: http://goneale.com/2009/03/04/using-metadatatype-attribute-with-aspnet-mvc-xval-validation-framework/
Nick Craver
This will have no effect. While you are right you can use a MetadataType attribute to point at a metadata class with more information, the framework doesn't use this attribute and an application must be specially written to handle this attribute, as the validation mechanism of data annotations does.
Steven
+2  A: 

I would probably use Damien Guards LINQ to SQL T4 templates, and modify the template to include the attributes you need. Then the attributes will be generated when you regenerate the classes.

Luhmann