Sometimes, it is necessary to override standard CRUD-operations in LINQ. The overridden operations can be useful when you want to:
• | Overload standard generated CRUD methods |
• | Include some validation rules to your CRUD procedures |
• | Improve your application security using database object accessing via stored procedures instead of direct access to the tables |
Entity Developer provides you the following approaches to implement this:
• | Define your own methods for CRUD operations |
In this article we consider an implementation of CRUD operation overriding, based on the stored procedures. For example, we have custom delete logic implemented in "Company_Delete" stored procedure. This methods contains specific rules of cascade deleting considered "PersonContact" table and some validation rules for deals between contact persons.
The procedure below is based on the model generated from our standard CRM_DEMO database.
To overload standard CRUD operations we have to perform the following steps:
1. | Go to the Database Explorer, find "COMPANY_DELETE" stored procedure and drag-n-drop it to the diagram. |
2. | The "Company_Delete" method will be added to the corresponding Model Explorer node. |
3. | Right-click the Company class and choose Stored Procedure Mapping option. |
4. | Choose Delete in the Behavior drop-down list and choose COMPANYDELETE method in the Method drop-down list. |
Also, you can add a stored procedure to the model when generating the model from the database. Just choose required objects on the Choose Database Objects page and then repeat steps 3 and 4.
Send feedback on this topic
© 2008 - 2024 Devart. All rights reserved.