Custom Validation

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
charlesboy
Posts: 6
Joined: Sun 23 Jun 2013 14:59

Custom Validation

Post by charlesboy » Wed 21 Aug 2013 03:27

Database :
mysql
Model Generation Template :
LinqConnect + Repository and Unit of Work + Data Annotations Metadata
Model :
Database-First Approach

what is the best way to define my validation ?
example validation:
compare one property to another, check if combine property already exist in my database or complex validation for my business rule :D
can you give some example?

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Custom Validation

Post by MariiaI » Wed 21 Aug 2013 11:43

To set the validation rules for entity properties please open your model, in the Model Explorer select the Data Annotations Metadata template in the Templates node (the Model Explorer can be opened by selecting Model Explorer from the Entity Developer submenu of the Tools menu). Set its Validation property to True. If there is no special need to use this template, you can set the Validation Framework property to Data Annotations for the LinqConnect template and use two templates in your solution - LinqConnect and Repository and Unit of Work.
After you have made these changes, select a particular class property on a diagram (or in Model Explorer) and initialize the needed attributes from the Validation section in the Properties window. Save the model to regenerate the code (the code will be regenerated with all necessary attributes).

Please refer to the corresponding topic in the Entity Developer documentation: Basic Workflows-> Code Generation-> Entity Property Validation.

If this information doesn't help, please specify the problems you are encountering in more details.

charlesboy
Posts: 6
Joined: Sun 23 Jun 2013 14:59

Re: Custom Validation

Post by charlesboy » Thu 22 Aug 2013 03:47

thanks, but it's only works for basic validation but how about for custom validation?
Is there a best practice way to use custom validation using entity developer?


if i using data annotation using inherited from ValidationAttribute http://msdn.microsoft.com/en-us/vs2010t ... opic2.aspx
where must i put the custom attributes for my custom validation, so when i regenerate the diagram it will not replace my entity property attributes Metadata...

if i can't use that approach, how about create custom template to generate service layer to validate my entity http://www.asp.net/mvc/tutorials/older- ... e-layer-cs


which approach do you suggest to work with entity developer?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Custom Validation

Post by Shalex » Mon 26 Aug 2013 09:24

Please navigate to Model > Settings > Attributes > select the assembly with the needed attributes and make sure that the needed attributes are checked in the window below, press OK.

After this, the corresponding attributes should be available in the Attributes menu of the class property.

Does this help?

charlesboy
Posts: 6
Joined: Sun 23 Jun 2013 14:59

Re: Custom Validation

Post by charlesboy » Thu 29 Aug 2013 02:47

so you suggest first Approach .... !

Post Reply