This is a migrated thread and some comments may be shown as answers.

override insert

1 Answer 72 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Trevor
Top achievements
Rank 1
Trevor asked on 15 Nov 2012, 03:22 PM
I need to create a sequential number for an identifier, but that sequential number is based on a group code(GGG-100,GGG-101,GGG-102,etc...).  I was going to do this just before the entity was committed to the database on the insert method by finding the highest number based on the group code and adding one. However, the insert method for the service is as follows.
Public Sub InsertChangeOrders(ByVal _changeOrder As ChangeOrder)
        'This is a callback method. The actual Insert is performed internally.
    End Sub
Is there some way to override the insert method to perform the lookup and create the number just before committing it to the database?

1 Answer, 1 is accepted

Sort by
0
Accepted
Alexander
Telerik team
answered on 20 Nov 2012, 02:10 PM
Hi Trevor,

Unfortunately you will not be able to do that in the service code. However, you could use the IInstanceCallbacks interface that OpenAccess provides and implement it on the classes for which you need to update the id manually.

To implement the interface, just create a partial class for your domain class in a new file (in order not to lose the changes if the autogenerated file is rewritten) and implement the three methods of the interface there:
Imports Telerik.OpenAccess
 
Partial Public Class ChangeOrder
    Implements IInstanceCallbacks
 
    Public Sub PostLoad() Implements IInstanceCallbacks.PostLoad
        'do nothing
    End Sub
 
    Public Sub PreRemove(objectScope As IObjectScope) Implements IInstanceCallbacks.PreRemove
        'do nothing
    End Sub
 
    Public Sub PreStore() Implements IInstanceCallbacks.PreStore
        'your code goes here
    End Sub
End Class

In this case you need to implement only the PreStore method, which is called during SaveChanges, right before the record is inserted to the database.
More information about this interface is available here. Hope that helps.

Greetings,
Alexander
the Telerik team
Telerik OpenAccess ORM Meets ASP.NET Web API. Read more.
Tags
General Discussions
Asked by
Trevor
Top achievements
Rank 1
Answers by
Alexander
Telerik team
Share this question
or