Reputation: 1336
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.
Upvotes: 3
Views: 1871
Reputation: 1
You can add permenant properties to your entities by creating partial classes. Support ADO.NET have a class Product
namespace Project.Data
public class Product{
/* some DB properties */
}
}
you can create something called a partial class in the same namespace to extend you class with additional properties and functions
namespace Project.Data
// Notice the keyword 'partial'
public partial class Product{
// Additional property
public int DisplayOrder {get; set;}
}
}
Upvotes: 0
Reputation: 21742
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.
Upvotes: 2