Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is OnValidate called in Linq?

Tags:

c#

linq

partial

I want to implement this partial method in my Linq table class.

partial void OnValidate(System.Data.Linq.ChangeAction action);

My hope is that is it called right before an insert. Can anyone tell me when the OnValidate method is called?

Update 1

I understand that I can check the enum to see what action causes it to fire. But WHEN does it get called? I need to know if it gets called each time someone submits changes or what?

like image 901
Anthony D Avatar asked May 20 '09 17:05

Anthony D


1 Answers

The OnValidate method for each changed entity, if it exists, will be called during SubmitChanges for the data context containing the entity. It will, thus, fire for all inserts, updates, and deletes done with that data context since the last time SubmitChanges was called (or the context created). If you need to distinguish your validation actions depending on the type of change you can key off the ChangeAction parameter to control the flow of execution.

like image 151
tvanfosson Avatar answered Oct 06 '22 00:10

tvanfosson