Last post Jan 27, 2008 07:23 PM by matt.tester
Jan 18, 2008 11:33 AM|ducquan|LINK
I have tried to insert and update objects to database. I use same method named "Save" for both of them in the Data Access Layer.
In Save method, I intend to use variable "Result" to hold the return value which is ID of the object has been updated or inserted. However, I do not know how to get this value
if I do not use store procedure. I have 2 questions:
+ Does anyone has any idea about this problem? I set auto-increase for SQL server to generate primary key
+ Is the way I implement the Insert and Update operation alright? (I think using method
CopyAllFields (see the detail below) is not a good way becuase if the object has so many properties, I have to write a lot when inplement this method.) Do you have any other way or recommendation?
Thanks for all your comments.
Item item = Item.CopyAllFields(SelectedItem);
LINQ : Return Value
Jan 27, 2008 07:23 PM|matt.tester|LINK
To get the Id back, you simply read the "Id" property of your object once "SubmitChanges()" has been called.
I had a similar problem (LINQ requires a new mindset [:D]), but found this
blog post which has a useful list of LINQ design patterns, including what you are trying to do.
Hope that helped.