Disabling SQL Generation in Entity Framework? -
i'm wondering if has found way disable ef using generated sql or disable ef executing ad-hoc sql statements. phrase way, i'd force entity framework only interact database using stored procedures defined mappings in .edmx file.
why want this?
i'm using ef orm in application interacts database using only stored procedures (due security requirements). it's easy forget define stored procedure mapping in .edmx file. when happens ef attempt generate ad-hoc sql @ runtime - results in runtime security error, ef try execute generated sql against database prohibits ad-hoc sql execution.
since of development work , unit testing done user account does have ad-hoc sql execution permission enabled, these runtime security errors missed.
some of options i've considered here:
switch orm - maybe there's orm supports stored procedures better, far haven't seen better alternative.
disable ad-hoc sql execution in sql on user account, use development. problematic though because unit tests, in cases, need use ad hoc sql inject test data, etc database. it's problematic because when i'm writing code it's convenient able execute ad-hoc sql statements against database (to manipulate data, inject test data, etc), , disabling ad-hoc sql execution mean switching between users or loosing ability.
somehow disabling ad-hoc sql generatiion in ef. seems far best option, continue developing, , testing user has sql execution permissions - , if forget stored procedure mapping, tests fail, or runtime error.
what run unit test different user development user not have ad-hoc privileges run setup , teardown steps of unit test development user.
it gives best of both worlds, both unit testing in same environment deployment , admin powers set said test.
Comments
Post a Comment