I'm currently creating an application that extracts data from lots of different data sources - most of these are development databases but some are live (I understand this is awful, but it's completely out of my control).
I'd like to protect myself from making modifications to these live databases, I'm therefore interested in making entities read-only.
My research tells me this isn't possible, but I'm anticipating a feature change or work-around may be available now. Has anyone achieved this?
I think that it's better to put that limit in the database instead of in the application. Create a separate user in the live database, that is member of the data_reader
role. That will give read access only to the database.
If you've tweaked the security settings and roles on the server you have to check more in detail, but as a default data_reader
will do.
A simple way to do it would be to override the SaveChanges()
method of the data context for those databases:
public override int SaveChanges()
{
throw new AccessViolationException(
"Don't mess with a live database during test");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With