Print Page | Close Window

How to implement pattern where Insert if New or Update if Exist

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3596
Printed Date: 13-May-2026 at 2:59am


Topic: How to implement pattern where Insert if New or Update if Exist
Posted By: ploc
Subject: How to implement pattern where Insert if New or Update if Exist
Date Posted: 27-Aug-2012 at 10:11am
Hello,

Give an Entity key that is combination DateTime and EmployeeId (int). Is there a simply way to implement Insert if New or Update if exist? So far I think there are two choices

1. Query first to see if it exists
2. Build a save interceptor 

Seems like such a common situation so maybe an existing way to do it already exists?

Thanks,

Phat



Replies:
Posted By: sbelini
Date Posted: 27-Aug-2012 at 12:02pm
Hi Phat,
 
I can't really see #2 as an option, and think #1 would be the proper way to handle it.
Remember that you need to load the entity prior to editting it, so you must query the entity. I assume you, somehow, would know the DateTime part of the composite key.
If it's not found, then you should create a new one.
 
Regards,
   Silvio.



Print Page | Close Window