This question is locked. New answers and comments are not allowed.
Could you help to suggest whether there is a easy to implement following requirement with OpenAccess ORM, SQL SERVER 2012?
Record all inserted/updated record in one transaction for following information:
Inserted Record: all data after inserted
Updated Record: all data before updated, all data after updated.
Record all inserted/updated record in one transaction for following information:
Inserted Record: all data after inserted
Updated Record: all data before updated, all data after updated.
3 Answers, 1 is accepted
0
Hi John,
In order to get the changes that will be performed during the next commit you could use the GetChanges method of your context instance. For your convenience I prepared the following code snipped demonstrating that approach.
Below you could find more useful information about handling transactions and accessing original values.
- Handling transactions and operating with the pending changes.
- Accessing original values after changes.
I hope this helps. Let me know if you need additional directions/assistance.
Regards,
Dimitar Tachev
the Telerik team
In order to get the changes that will be performed during the next commit you could use the GetChanges method of your context instance. For your convenience I prepared the following code snipped demonstrating that approach.
using (EntitiesModel context = new EntitiesModel()){
// set this property if you need to check the original value of some of your records context.ContextOptions.MaintainOriginalValues = true; // perform some CRUD operations over your data here ...
try { // getting the changes Telerik.OpenAccess.ContextChanges contextChanges = context.GetChanges(); // getting the new records IList<SomeEntity> inserts = contextChanges.GetInserts<SomeEntity>(); // getting the records that will be updated IList<SomeEntity> updates = contextChanges.GetUpdates<SomeEntity>(); // getting the records that will be deleted IList<SomeEntity> deletes = contextChanges.GetDeletes<SomeEntity>(); // try to commit the transaction context.SaveChanges(); // log the inserts, updates and deletes from the above lists here // if you need to check the original value before being updated foreach (var item in updates) { // getting the original value of “someProperty” object originalValue =
db.GetOriginalValue<object>(item, "SomeProperty"); } } catch (Exception) { // cancel the transaction context.ClearChanges(); throw; }}Below you could find more useful information about handling transactions and accessing original values.
- Handling transactions and operating with the pending changes.
- Accessing original values after changes.
I hope this helps. Let me know if you need additional directions/assistance.
Dimitar Tachev
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
0
john
Top achievements
Rank 1
answered on 18 Dec 2012, 01:29 AM
Hi,
I think you can read http://www.simple-talk.com/sql/learn-sql-server/introduction-to-change-data-capture-(cdc)-in-sql-server-2008/
I need the above solution. I think telerik also can add the similar solution in future.
I think you can read http://www.simple-talk.com/sql/learn-sql-server/introduction-to-change-data-capture-(cdc)-in-sql-server-2008/
I need the above solution. I think telerik also can add the similar solution in future.
0
Hello John,
Ivailo
the Telerik team
You are right that this is one possible direction for further simplifying your scenario.
However, bear in mind that a customization like this one is possible even now with OpenAccess ORM, as the changes are mostly in the database and can be done manually. Also you can achieve similar results with triggers or stored procedures.
Let us know if you have any additional feedback.
Ivailo
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.