0

I'm working with Linq to perform a series of SQL queries on a database. When we call SubmitChanges() it automatically determines whether it should update or insert a record. However sometimes this automatic method isn't that helpfull.

For example, I've had issues with composite primary/foreign keys on a table and when Linq should have performed an Update, it most exclusively went out performing Insert statment, which was of course blocked by the database when a specific key composition already existed causing a headache and waste of time...

Therefore I was wondering if is there a way to force an Update over an "usually Linq self-determined" Insert statement. Kinda like there is .Attach() InsertOnSubmit() is there a counter part to Update?

Note: As anyone noticed Linq to Sql takes Delete requests in last place regardless of you called them before or after another insert or update statement, is there any way within Linq to change this?

Thank you for you time.

Fábio Antunes
  • 16,984
  • 18
  • 75
  • 96
  • As for your note, I dont think so. I ran into this years ago (search my questions). – leppie Jul 15 '14 at 06:43
  • get the item first by its composite pk then perform the update – Yuliam Chandra Jul 15 '14 at 06:45
  • @leppie: I'm pretty sure you mean this: http://stackoverflow.com/a/797232/114298 Using a transaction scope :) – Fábio Antunes Jul 15 '14 at 06:49
  • @YuliamChandra That's what I ended up performing with a few tables, adding an extra primary (and now the only primary key) within the table. Unnecessary if Linq was able to pick up composite keys (least I think it can't), or if I knew of others means to make it aware of it. – Fábio Antunes Jul 15 '14 at 06:50

0 Answers0