Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Database First Import
Message
De
11/01/2013 13:11:03
 
 
Information générale
Forum:
ASP.NET
Catégorie:
MVC
Versions des environnements
Environment:
C# 5.0
Database:
MS SQL Server
Divers
Thread ID:
01562068
Message ID:
01562189
Vues:
33
>>>>>I'm getting my feet wet with ASP.NET MVC. I'm using MVC4, VS2012, and MVC Scaffolding. I pulled in an existing database using the provided wizard. The generated model does not include annotations like [MaxLength] or [Required]. Did I miss something or is that not a feature of the wizard? Seems like a pretty big missing feature if you ask me. Without it, I have to enter all the annotations manually if I want MVC to do the validations.
>>>>
>>>>You will need to add a partial class and a metadata class :http://msdn.microsoft.com/en-us/library/cc488527(v=vs.100).aspx
>>>>
>>>>Seems like a lot of hassle but if it was not done this way then you would lose any custom validation attributes when the model rebuilds...
>>>
>>>I have run into the information about the partial class before, but I couldn't find an answer to the question about the wizard capabilities. Just to confirm... you are saying I did not miss anything. The database importer does not generate any annotations with basic structure information. Correct? That seems extremely limited to me. I may have found something that helps, or if it doesn't, maybe there is something out there: http://blogs.msdn.com/b/lgmorand/archive/2010/12/31/entity-framework-template-t4-and-data-annotations.aspx
>>
>>Modifying the T4 template may be one approach. But consider that you may want to apply other validation the type of which is not inherent ,or at least obvious, from the SQL table structure. As an example, you may want to use a regex() to valid password or email formats. You might even, at some point in the future, want to swap out the SQL/EF data layer for something different. In those circumstances, whilst requiring a bit more effort, using the metadata approach may be preferable.....
>
>I use this for email
>
>
>    [Email]
>          [StringLength(100)]
>          [DataType(DataType.EmailAddress)]
>          [DisplayName("Email")]
>          public virtual string Email { get; set; }
>
>where the first attribute is taken from DataAnnonations library which can download using nuget.

Fine. But that doesn't change my point that you can't determine the required validation from the SQL field
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform