Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Entity Framework class that was derived from the database layout. I was wondering if there was any problems by extending the class by creating another cs file and using the same public partial class to add the additional properties?

Much like you would do when creating a file for data annotations. I have tested and it works for my MVC application. It allows me to pass some dynamic properties to the view model while still using the original model from EF 'and additional file I created'.

Does this pose any problems, or is there a better solution?

share|improve this question

This is the preferred method of extending the EF data classes.

You can add almost anything. I had a situation where I needed to use different annotations (replacements for the validation, as the defaults weren't sufficient for my needs).

Microsoft provides plenty of examples to do this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.