New Posts New Posts RSS Feed: EF DataAnnotations vs Devforce DataAnotations
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

EF DataAnnotations vs Devforce DataAnotations

 Post Reply Post Reply
Author
rbautistaole View Drop Down
Newbie
Newbie


Joined: 01-Apr-2011
Posts: 37
Post Options Post Options   Quote rbautistaole Quote  Post ReplyReply Direct Link To This Post Topic: EF DataAnnotations vs Devforce DataAnotations
    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
 
 
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
rbautistaole View Drop Down
Newbie
Newbie


Joined: 01-Apr-2011
Posts: 37
Post Options Post Options   Quote rbautistaole Quote  Post ReplyReply Direct Link To This Post 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. :)
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
rbautistaole View Drop Down
Newbie
Newbie


Joined: 01-Apr-2011
Posts: 37
Post Options Post Options   Quote rbautistaole Quote  Post ReplyReply Direct Link To This Post Posted: 18-Jul-2012 at 9:03am
Well, seems to me that DevForce thinks in another way:
 
 
"We recommend that you use use DevForceVerification unless you have a compelling reason to do otherwise (e.g., you have a large amount of code that already uses the .NET attributes and facilities). DevForce verification provides a superset of the capabilities provided by .NET validation."
 
Regards
 
Back to Top
mgood View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 18-Nov-2010
Location: Emeryville, CA
Posts: 583
Post Options Post Options   Quote mgood Quote  Post ReplyReply Direct Link To This Post 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.
 
 
Back to Top
rbautistaole View Drop Down
Newbie
Newbie


Joined: 01-Apr-2011
Posts: 37
Post Options Post Options   Quote rbautistaole Quote  Post ReplyReply Direct Link To This Post 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.
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down