1

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?

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Jan 29, 2016 at 16:44

1 Answer 1

1

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.

answered Jan 29, 2016 at 21:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.