How to hide a database column in an entity model?

I am using Entity Framework 4 and ask a question:

I have a password column in my database that I want to manage using custom SQL. Therefore, I do not want the model to know about it.

I tried removing the property in the Mapping Details window, but then received a compilation error:

Error 3023: problem with displaying fragments starting from line 1660: User.Password column in the table. The user must be mapped: it has no default value and no null value.

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

Error 3004: a problem with displaying fragments starting from line 1660: no matching was set for the properties of User.Password, User.Salt in Set Users. An object with a key (PK) will not be rounded if: Entity is of type [UserDirectoryModel.User]

Any ideas please?

Thanks Nick

+7
entity-framework entity-framework-4 edmx
source share
2 answers

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

+4
source share

You can simply mark a property as private using the Properties panel in the EDMX designer: in the Code Generation section, it has the Getter and Setter parameters, which you can change from Public to Private.

+10
source share

All Articles