orm - Override behaviors in Entity Framework -


we have data model has requirements. find way make these requirements transparent possible while using ef.

first, model must support soft-delete. i've seen questions around , think relatively straight forward.

second, have "insert only" policy. means no updates. when update made, new entry must inserted instead. able treat operation update, , have framework change insert behind scenes.

third, due #2 when query, need order descending on identity column , return first record only. when doing query returns many records. essentially, creates version history.

fourth, don't want have implement logic in each query. nice have framework can treat each query if normal crud type transaction.

has implemented such data model in ef? techniques did use?

i'm aware of can done in views and/or sprocs, if use views have maintain relationships manually (ef can't read relationships through views). triggers possibility, our dba's want few triggers possible, , have extensive review policy on triggers takes long time accomplish. i'd rather not use trigger if don't have to.

i work in database first approach, use dbcontext.

edit:

given ladislav's comments below, i'd interested in comments other orm's may able handle these requirements.

  1. this possible conditional mapping additional column used differ deleted records , custom sql command / mapped stored procedure every entity requiring soft delete perform update instead of delete.
  2. i doubt ef handle transparently. if modify attached instance loaded database perform update. can again map stored procedure perform insert instead of update change not reflected in application logic. have dispose context , reload data new context instance see changes correctly. better option force application somewhere clone entity , insert clone new one.
  3. ef not allow adding such condition autogenerated queries transparently unless map view or custom sql query. once use view or sql query must use sql commands or stored procedures insert, update , delete operations. using custom sql query has same disadvantages using views.
  4. if don't use sql query, have write query example in form of custom reusable extension method , use everywhere aware eager or lazy loading not reflect this. in case of eager , lazy loading versions.

stored procedure mapping requires edmx. custom sql command , query mapping requires edmx , without other commercial tool have manually maintain edmx.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -