3

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes I think it is the solution. Thank you.
Please could you look at stackoverflow.com/questions/7868230/… I did what you said but I still have a problem.
@Patrik I see you have already found the solution. The code in the article I like to has a similar solution as you found yourself. Le me know if you get stucked again
The link doesn't work anymore => This domain has recently been listed in the marketplace.
0

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;}
   }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.