architecture - N-Tier - responsbility location for insert vs update -


i'm creating application split data layer (using repository pattern & ef 4.0), business layer (poco's additional logic) , service layer (which exposed client using wcf).

when i'm saving record database need check , see if i'm updating existing record or inserting new one. should responsibility lie - in service layer lifetime of object explicitly managed, or in data layer saving record implicitly determine action take.

all comments welcome - can't decide myself!

my first thought think entity framework should able figure out itself, i'm not 100% sure that.

barring ef doing you, put logic in repository. pass in customer object repository so: myrepository.save(mycustomer);

and in save method of customer, checks if customer has id assigned or maybe can ask ef track state, , insert or update. way, regardless of save gets called--web service, ui, etc. logic taken care of.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -