ASP.net webforms data annotations - is using dynamic data needed? - asp.net

I'm hoping to generate my server-side and client-side validation (ish) using meta data on our entity classes.
I've been reading up on creating validators to use the meta data from data annotations.
However recently I've also been reading up about dynamic data.
Is my understanding corret in that the prescribed route to use data annoatations within web forms is to use asp.net dynamic data? As the custom validator tutorials seem a little old.
However, we are not using data binding as we are using the repository pattern with entity framework - does this mean we cannot use dynamic data?

The validation annotation derives from the System.ComponentModel.DataAnnotations namespace. You can use the Dynamic Data one for ASP.NET web forms, or, write your own.

Related

When I create classes in model, does it automatically create database tables?

I just started learning about asp.net mvc. My previous expierence is in python django. I was wondering when I make classes in the models file, it will automatically create those tables for me? Sorry I am a real beginner.
No, It just maps your input data and enables controllers to manipulate data and send to view. In order to fill data into database you should use LINQ to SQL and data entity framework.

When to use dynamicfield in gridview?

Allow me to ask a stupid question about dynamicfield. When and why to use it?
Thank you in advance!
Represents a data field displayed in a data-bound control that uses ASP.NET Dynamic Data features.
ASP.NET Dynamic Data is a framework that lets you easily create ASP.NET Web applications data-driven. To do this, it automatically metadata data model and runtime deduce the behavior of the user interface..
Link : http://msdn.microsoft.com/fr-fr/library/system.web.dynamicdata.dynamicfield.aspx

ASP.NET SPA with a legacy domain objects

Looking at the Single page application beta in the MVC 4 I don't see how I can use my legacy domain objects as the model. It seems to require that the model use the entity framework to using DbDataController to get the data etc.
I do not understand the entity framework so I am probably missing something.
How can I use my legacy domain (with it's own DAL) in the SPA of MVC 4?
This was answered by somebody else in an ASP.NET forum.
You won't be able to use anything other than EF if you want to use some of these RAD tools. However, SPA builds on top of MVC, so you should be able to build your own version rather easily. The important components would be building a DataController on top of ApiController and a js consumer for the service provided by your DataController. It's possible that if you were to format your models in the same format as the EF output (I think it's just OData) you could use upshot.js, as well and only have to implement a DataController to format your domain models.
I will add the following after working with it for a couple of days that you could, theoretically, use it if the following are handled/fixed by you and future versions of the SPA.
You can create a controller that inherits from System.Web.Http.Data.DataController (and maybe even ApiController). The objects it returns then must just have a property decorated with the System.ComponentModel.DataAnnotations.Key() attribute. I can get the views to work fine but some of the more advance features, like grouping, I am having problems with.
Readonly property will not be returned I guess because of a problem with the current JSON serializer used. Should be fixed.
Of course the entire object will be serialized which can be very problematic if your domain objects are complex with child objects. Especially if some of those objects have serialization issues of their own.
Related to the complex serialization the current JSON serializer cannot handle circular references in the domain objects referenced.
I have also run into problems getting update/deletes/inserts being posted back when using my own Controller that inherits from System.Web.Http.Data.DataController (the examples use DBDataController).

ASP.NET MVC Custom ModelMetadataProvider and ModelValidatorProvider

In my ASP.NET MVC application, I have metadata based model defined in database. I have a custom object defining the metadata of the data and uses dataset for DTO. To display this, I am planning to write a custom ModelMetadataProvider and ModelValidatorProvider.
Is this the right approach?
Any pointers on custom ModelMetadataProvider and ModelValidatorProvider?
The last day or so I was trying to figure out the same.
It seems that writing a custom ModelMetadataProvider and ModelValidatorProvider is the way to go if you have metadata / validation configuration stored on database, some file or wherever.
I found this a great starting point.
Did you in the meantime already hacked together a solution?
HTH,
Manu.

Validation in the business logic - ASP.NET Web Forms

In reading up on ASP.NET MVC I came across some wonderful examples of validation where the business rules were associated with the model and the UI merely displayed the set of errors and flagged the form elements associated with invalid input. I think it makes fantastic sense to keep this logic in a single place rather than have every form perform its own unique validation.
Is it possible to achieve this separation in an elegant manner with an ASP.NET Web Application project (webforms)? I can keep the validation rules in the business logic layer and I can have methods that perform validation and return a set of errors. But I can't figure out a good way to flag problematic controls on the UI side.
In MVC the form elements and model are implicitly linked by property names. Should the UI in ASP.NET reference the unique property names of the model (either as ID/name or as a custom attribute)? Should the UI have access to a manually-generated mapping of control names to property names?
A way I like to do it is to create CustomValidators, bound to control on the screen and I call my BL validations in the OnServerValidate event. That way, my validation logic stay in one place.
Hope it will help
I'm sure I remember hearing some where that some improvements around Data Annotations would be available for WebForms in .NET 4.0, but after trying to search for it online I'm starting to think I dreamt it.
Although I did find this post of a guy that 'rolled his own':
http://adventuresdotnet.blogspot.com/2009/08/aspnet-webforms-validation-with-data.html

Resources