New Posts New Posts RSS Feed: How to implement pattern where Insert if New or Update if Exist
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

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

 Post Reply Post Reply
Author
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Topic: How to implement pattern where Insert if New or Update if Exist
    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.
Back to Top
ploc View Drop Down
Newbie
Newbie


Joined: 16-Jan-2012
Posts: 1
Post Options Post Options   Quote ploc Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down