Page 1 of 1

Custom Validation

Posted: Wed 21 Aug 2013 03:27
by charlesboy
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?

Re: Custom Validation

Posted: Wed 21 Aug 2013 11:43
by MariiaI
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.

Re: Custom Validation

Posted: Thu 22 Aug 2013 03:47
by charlesboy
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?

Re: Custom Validation

Posted: Mon 26 Aug 2013 09:24
by Shalex
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?

Re: Custom Validation

Posted: Thu 29 Aug 2013 02:47
by charlesboy
so you suggest first Approach .... !