I am using Entity Framework 3.5, while inserting a record i want to return the unique identifier with entity framework. How to do that?
+3
A:
After calling savechages the new id will be stored in the entity. so you can retrieve from the entity.
Saravanan I M
2010-03-07 03:57:55
+3
A:
More generally, "To ensure that objects on the client have been updated by data source-side logic, you can call the Refresh method with the StoreWins value after you call SaveChanges.", per MSDN.
Hightechrider
2010-03-07 04:24:38
That's unnecessary, for an ID, anyway. `SaveChanges()` alone is enough.
Craig Stuntz
2010-03-08 14:23:44
Hence the phrase "more generally".
Hightechrider
2010-03-08 15:35:35
Actually, I have to take back what I wrote. With EF 1 and server-generated GUID IDs, they won't be returned on `SaveChanges` and a `Refresh` *would* be necessary. For `int` or `long` IDs, however, a `SaveChanges` alone is enough.
Craig Stuntz
2010-03-09 14:31:35
A:
One way that I have taken to working is, when sending a record to my DataLayer/Business Logic Layer, is to have the DL/BLL do the update/insert, then retrieve the record back from the DB and return it with a boolean indicating success or failure.
That way, I can immediately refresh the record in the interface with the written one so I can be sure the record actually went in how it should have.
hermiod
2010-03-07 20:14:31