Print Page | Close Window

EF DataAnnotations vs Devforce DataAnotations

Printed From: IdeaBlade
Category: Cocktail
Forum Name: Community Forum
Forum Discription: A professional application framework using Caliburn.Micro and DevForce
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3544
Printed Date: 20-Sep-2025 at 7:34am


Topic: EF DataAnnotations vs Devforce DataAnotations
Posted By: rbautistaole
Subject: EF DataAnnotations vs Devforce DataAnotations
Date Posted: 16-Jul-2012 at 6:36pm
In examine TempHire app i see that your entities are decorated with the EF DataAnnotations (Required, StringLenght) instead the DevForce Data Annotations (RequiriedVerifier, StringhtLenghVerifier). I used too the EF DataAnotattions because the EF DataAnotations place constraint over the DataBase (NOT NULL, string sizes) and the DF not.
 
Do you recommend EF DataAnnotations over DevForce DataAnotations?
 
thanks
 
 



Replies:
Posted By: mgood
Date Posted: 16-Jul-2012 at 6:58pm
You are pretty much forced to use .NET Data Annotations if you do Code-First. Unfortunately, the data annotation attributes perform double duty. They describe your mapping as we'll as perform validation. If you add DF verifiers on top, you get duplicate validation errors because DF already observes the data annotation attributes.

So it's not really a recommendation, but rather you don't have much of a choice with Code-First.


Posted By: rbautistaole
Date Posted: 16-Jul-2012 at 8:05pm
A Suggestion to DevForce would be that your Verifiers to describe the mapping and validating as the DataAnnotations.
 
May be you can to influence on the DevForce team. :)


Posted By: mgood
Date Posted: 16-Jul-2012 at 8:19pm
The DF Verifiers go back to before .NET had comprehensive validation attributes. To some extent they are superseded by the .NET attributes today. They are still useful if you wish to implement your own verifiers, but for standard type validation the .NET attributes pretty much cover that space.


Posted By: rbautistaole
Date Posted: 18-Jul-2012 at 9:03am
Well, seems to me that DevForce thinks in another way:
 
From documentation in http://drc.ideablade.com/xwiki/bin/view/Documentation/validation-generate-attributes - http://drc.ideablade.com/xwiki/bin/view/Documentation/validation-generate-attributes
 
"We recommend that you use use http://drc.ideablade.com/xwiki/bin/view/Documentation/validation-generate-attributes -
 
Regards
 


Posted By: mgood
Date Posted: 18-Jul-2012 at 10:16am

Let me ellaborate on what I said. I realize it was a bit short.

The above recommendation was written before Code-First and it still holds for Model-First and DB-First. In the latter two you generally select one or the other, because DF generates the code and not the developer. In this case we still recommend DF Verification, because it is a superset and there's no compelling reason to mix .NET attributes with DF Verifiers.
 
In Code-First you have options. Mapping and validation are two seperate concerns and it is unfortunate that Microsoft decided to fold them in one with the data annotation attributes. DF keeps them seperate for good reasons, so we don't want DF Verifiers to describe the mapping.
 
As I said there are options with CF, so let's look at them. There is the purist approach. In the purist approach you'll leave your entities free of attributes alltogether. To describe the mapping you rely on EF conventions and the Fluent API, where conventions don't apply. This way you don't use the data annotation attributes at all. Now you can use DF Verifiers to describe all your validation rules. DF also allows you to define the validation rules outside of the entity class, leaving your entity classes free of validation attributes.
 
Most developers use a combination of EF conventions, data annotation attributes and Fluent API. It's less code to write in the end. In this case you are in the situation where you find yourself having a "large" amount of code that already uses .NET attributes. The word "large" is relative here, but you get my point. You start with the .NET attributes. At any point you can augment with DF Verifiers when it gets past basic validation or you can use the Cocktail custom validation approach or a combination of all three.
 
There is no clear line in the sand, or at least we haven't settled on one. In TempHire I follow the most common approach. I started with EF conventions and then added data annotations attributes, where EF conventions don't apply and then used the Fluent API for DB Initialization. This is the natural path most developers follow. If you follow this path then you'll primarly use .NET validation and resort to DF Verifiers or Cocktail custom validation when you reach the limits of .NET validation.
 
 


Posted By: rbautistaole
Date Posted: 18-Jul-2012 at 11:20am
Thank you very much.
 
This is a more clear explanation.
 
Now, you say "The above recommendation was written before Code-First and it still holds for Model-First and DB-First"
 
I think that is necessary to divide the DEVFORCE documentation in two big groups: "Code first" and "Modelfirst or dbfirst". I think that would be more clear if each group have the same topics as now: Start, Model, Query, Display, Create Modify and Delete, Validate etc. I feel that exist specific tips and tricks to each approach. May be some information is shared.
 
thanks again.
 



Print Page | Close Window