.net - options for a read-only (no change tracking, SaveChanges should throw) EFv4 model? -


note: vs2010 / .net 4, without sp1 beta @ moment, if in sp1 addresses this, it'd still great know about. :)

i have particular database want read never write to. don't see in properties of model (looking in ef designer) mark read-only.

certainly looks simplest thing add partial class generated objectcontext subclass (class foomodel : objectcontext) override savechanges(saveoptions) , have throw (maybe hooking savingchanges , throwing work too, haven't tried either). wouldn't disable change tracking, , afaict i'd have loop through entity sets on context instance creation mark them read-only (although that's perf issue not critical making sure changes don't persist).

certainly there's other options having connection string connect user has read access, wonder options available ef designer/model/instance perspective having 'read-only' object contexts?

there few ways make model readonly

  • entity without primary key read-only
  • entity mapped db view (without primary key) read-only. same applies if use definingquery in ssdl directly.
  • entity mapped queryview in csdl read-only. queryview works on top of other entities generaly doesn't solve problem.

your suggest permissions user accessing database looks secure way. if want disallow saving changes overriding savechanges , throwing notsupportedexception looks solution.

because work read-only entities can improve query performance using mergeoptions.notracking.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -