Pergunta

I would like to implement checking of object data when inserting or submitting the object to sql. Is there some OnInsert or OnSubmit function that I could implement/extend for the automatically generated linq-to-sql-classes, or some other solution?

The normal way to do this would be to put restrictions, check-constraints, triggers and stored procedures in the sql server db, but I would like to avoid that in order to keep my code in one place and get syntax checking etc.

(I think checking of unique indexes and foreign keys are better implemented directly in the sql db)

Foi útil?

Solução

You can use the OnValidate()function with the LINQ-to-SQL Entity's partial class. OnValidate() will then be called during SubmitChanges() but before the data is sent to the database.

More info on... stackoverflow.... Validate Linq2Sql before SubmitChanges()

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top