Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide a database column in the entity model?

I'm using the Entity Framework 4 and have a question:

I have a password column in my database that I want to manage using custom SQL. So I don't want the model to know anything about it.

I've tried deleting the property in the Mapping Details window, but then I got a compilation error:

Error 3023: Problem in mapping fragments starting at line 1660:Column User.Password in table User must be mapped: It has no default value and is not nullable.

So, I made the column nullable in the database and updated the model. Now I get this error:

Error 3004: Problem in mapping fragments starting at line 1660:No mapping specified for properties User.Password, User.Salt in Set Users. An Entity with Key (PK) will not round-trip when: Entity is type [UserDirectoryModel.User]

Any ideas please?

Thanks, Nick

like image 946
Nick Butler Avatar asked May 16 '10 10:05

Nick Butler


2 Answers

You could just mark the Property as Private using the Properties pane in the EDMX designer: Under the code generation option it has Getter and Setter options that you can change from Public to Private.

like image 155
Ian Mercer Avatar answered Oct 16 '22 05:10

Ian Mercer


One way to fix this is to create a view of your user table that does not include the password column. Then use the view in your model rather than the table.

like image 36
Shiraz Bhaiji Avatar answered Oct 16 '22 05:10

Shiraz Bhaiji