How to generate validation checks for constraints in Entity Framework?

I have my first database script, so EF generates entity classes from an existing database, tables in my db have many check constraints that validate that the inserted / updated values ​​meet certain criteria, my problem is that EF does not work 'generate any code for these constraints, so these constraints will only be checked against the database. I want these checks to be done from the generated classes, so if an error occurs, it will be raised without accessing the database.

I know that I can change the T4 template for my model, so I add my constraints to the generated classes, but any code I write will be hardcoded for each specific table in hand based on the constraint code template, which is what I need. is a solution that adapts the generation to any form or pattern of constraint code. To explain more, here are 2 samples from two different constraints:

([ADT_OPT_UPD]>=(0) AND [ADT_OPT_UPD]<=(2))
([INS_USR]>=(0))

      

These are two examples of constraints I have in my database, and it can get complicated by adding more ORs ORs etc., so I need a generation method that adapts to any validation constraint pattern.

I was thinking about writing a parser that parses the constraint and generates the equivalent C # code, but such a parser would have to handle all possible cases for the shape of the constraint code, and this is too much for me to do now as I don't have time for that ... So, is there another solution, and if this is the only way to do it, is there any tool or library that can help me with this task?

+3
c # .net entity-framework


source to share


No one has answered this question yet

Check out similar questions:

1758
How do I generate a random int?
867
How can I generate random alphanumeric strings?
783
Entity Framework vs LINQ to SQL
758
Entity Framework 5 Record Update
756
Failed to check for one or more objects. For more information, see "EntityValidationErrors Property".
630
Fastest way to insert into Entity framework
613
Implementing INotifyPropertyChanged - is there a better way?
515
How can I get the ID of the inserted entity in the Entity framework?
461
How do I view the SQL generated by the Entity Framework?
401
Entity Framework Service Provider not found for ADO.NET Provider with invariant name 'System.Data.SqlClient'



All Articles
Loading...
X
Show
Funny
Dev
Pics