Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding attributes to properties in the Linq2Sql DBML

We are working with a database containing metadata on all database tables and fields used in our applications. From this metadata, we generate code that contains partial classes, extending our Linq2Sql entities.

We had the idea of adding an "obsolete" flag in our metadata, which should in turn add the Obsolete-attribute to the flagged properies in the Linq object. (generating warnings in our code using old fields)

Is this type of extension possible in a partial class? To just add an attribute to a property in a partial class file? This sounds a lot like a "partial property", something I tought didn't exist in .NET.

like image 251
Joachim VR Avatar asked Nov 14 '22 02:11

Joachim VR


1 Answers

Yeah, check out the MetadataType attribute.

Good example here. In this context, they want to add attributes for the purposes of validation, but no reason you couldn't do the same to indicate obsolescence.

like image 62
Tom Lianza Avatar answered Dec 25 '22 22:12

Tom Lianza