In EF 4.1 RC1, I have a simple entity like say Category, with a property ID int. Can I make that a read only property and still have it work?
If not, how do you protect the PK/FK?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One way is to define your ID property like this:
… then define your DbContext class in the same assembly as the “Category” class. It’ll have write access to the property, but classes outside of the assembly won’t.
If you need to define your DbContext in a separate assembly, you can use the InternalsVisibleTo attribute to let that assembly see the internals of your “Category” class.