I’m creating a WCF service that transfers entity objects created via entity framework. I have a User entity that maps to a User db table. There are certain User fields (Password, DateCreated, etc) that I don’t want to expose to the client but, because they are non-nullable in the db, Visual Studio requires mappings. Setting these properties as private seems like a good workaround but these properties are converted to public when consumed by a client.
Is there a way around this, or a better approach to take? I’d rather avoid changing these fields at the db level just to make EF happy.
You could always implement
IXmlSerializableon the entity object. Then, you would be able to dictate the structure of what is sent to the client (the client would get a different representation, obviously).Either that, or if you can, add the
DataContractattribute to the type, and theDataMemberattribute to only the properties you wish to send over the wire.