I need to use the users table from a parent site, is it possible to map the user table using the fluent API and have it be read only?
2 Answers
In case of EF code first you can't directly make it "read-only" but you can design your code to not expose DbContext
and related DbSet
outside of your DAL logic so rest of the application cannot add a new user.
In case of EDMX based mapping you can make it read only by mapping it as a custom SQL query (or database view) where insert, update and delete operations are not supported until you map them custom SQL commands or stored procedures.

- 360,892
- 59
- 660
- 670
According to a comment on ScottGu's blog, no.
Right now we don’t support read-only (or semi-read-only) properties in Code First but this is an interesting suggestion that I will talk with our design team about. In general the Entity Framework doesn’t have support for marking something as “read-only” so we may have to wait for another major .NET framework release to get this working. For now, you will have to add business logic in your entity to allow the property to be set only once.
Jeff Derstadt
Entity Framework Code First Team

- 42,637
- 17
- 112
- 171