I would like to ask another different question, how to create Auto increment ID, and should start from the max column Id.
Auto increment ID
Answers approved by DevExpress Support
Hello,
You can derive your persistent object from the built-in XPObject class that provides an auto-incremental integer key. If this solution does not meet your needs, please describe your task in greater detail.
For instance, you can refer to the Session.Evaluate problems ticket to learn about an alternative approach to query the max number in a table. Taking your code into account, the following code worked fine in my tests:
C#Public Overrides Sub AfterConstruction()
MyBase.AfterConstruction()
EmpKey &= Convert.ToInt32(Session.Evaluate(Of Employee)(DevExpress.Data.Filtering.CriteriaOperator.Parse("Max(EmpKey)"), nothing)) + 1
End Sub
In addition, I suggest you study the following example: How to get the maximum or minimum object's value from a collection.
Unlike the constructor, which is called for both cases when a persistent object is loaded from the database and is created manually, the AfterConstruction method is called only when a new object is created.
Here is some useful documentation on this method: http://documentation.devexpress.com/#Xaf/CustomDocument3258
The OnSaved method is inappropriate here, because the transaction is closed at this time already. You should not generally use this method. Take special note of the OnSaving method instead.
You are always welcome!
P.S.
Once your question has been resolved to your satisfaction, mark the corresponding answer as a Solution. Your question status will immediately become Closed.
http://devexpress.com/Support/Center/FAQ
=================================
Join the XAF and XPO Fan Club!
=================================