简体   繁体   中英

Adding Attributes to properties in classes generated by ADO.NET entity data model

In brief...

I'm trying to find a way to add some attributes to the properties in the classes created through the ADO.NET entity data model in a way that when I require updating of the database do not always have to add them manually.

Details ....

I created a class for creating a form that is dynamically filled with controls for editing properts. The input value is the object with public properties to edit. The output is a Control like panel control that contains dinamically created controls for properties editing. This concept can be easily applied on asp.net, Silverlight or classical stand alone applications.

Creating controls is based on the type of the property. For example if the property is some kind of integer data type, then the class creates a TextBox control. if it is Bool then creates a checkbox, if it is a key to referenced table than ComboBox is created or some other kind of external window to make a selection.

In some cases the data type is not sufficent to describe the content of the property and consequently I decided to use Attributes (C#).

My code is working perfectly but when the time for updating the source database comes (when I recreate the .edmx file) I loose all my Attributes and META-parameters.

I am wondering if somebody has an idea what to do to make this job more automated and simplified for maintenance.

Maybe extending the created classes is the solution but it is an additional job to do every time something on the source is changed.

You could use a metadata class for your entities and attach the properties to the metadata class instead

this article describes how to use metadataclass attributes for validation but once you know how to get hold of the attribute you should be able to use your existing code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM