ASP.NET MVC Custom ModelMetadataProvider and ModelValidatorProvider - asp.net

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.

Related

Creating Classes from Exising Database

I have ben following through a tutorial that shows how to get started creating a Web Forms Application in ASP.NET...and have got to the part where you create Data Classes. These assume you are starting from scratch and generating the database from code - however - I already have a database created and populated from elsewhere.
Entering line by line to create the Class for each table seems very laborious. (I'm using VB.Net and VS 2013 by the way)
Q1. Can anyone help by suggesting a more automated way of doing this? Surely there is a tool to grab the schema?
Q2. Although the tutorial mentions Entity Framework and Code Behind briefly - having done some reading and research - I am very confused by all of the different terms for data access. Am I using ADO.NET ?? Is the methodology called Code Behind as opposed to something else? Are there better ways to connect to a database and Read/Update/Delete records.
Q3. If I want to use a Data Grid to show the data do I use the generated classes to do this - or just 'bind' the grid directly to the database?
I have been a developer for 40 years but the newer .Net models are causing me some confusion so any advice gratefully received. (and any simple books or tutorials that can be suggested would be helpful).
Thanks
Q1: What you want is to generate "EF Designer from database" by using a Entity Data Model.
In your project add a new item and look under "Data".
What this technique does is auto generating entity classes from your predefined database.
Q2: I suggest you read Getting started with Entity Framework. "Database First" is just a description of how you want to use the Entity framework - by saying you already have a database structure.
Q3: In this case if you use Entity Framework and the "database first" mechanism to generate entities you can databind the gridview from the result of a entity LINQ query, please see this example: Tutorial: Databinding

How to make crud operation in asp.net mvc aspx without database nor entity framework

All tutorials I can find is with database or entity framework. I just want a simple class as model with field creation and update from the view and using .aspx template.
Can somebody give me as simplest example as possible or point me an article on the web I've bee googling all day long without finding any.
Simply use an EF Code First tutorial and remove the calls to DbContext - without DbContext, the entities are simply POCOs. Replace those calls with however you plan to persist/read your data.

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

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.

ASP.NET Entity Framework - Create Trigger Programatically

I posted this question on the ASP.NET forums, and was eventually directed to post the same question here.
Original asp.net forums post: http://forums.asp.net/t/1774923.aspx/1?Database+Generated+DateTimes
I'm trying to add CreatedDate and ModifedDate to my Code First models. If this were database first I would have added a GETDATE() default value to both of these. A few options were presented on how to do this using C.F.. However, I think the cleanest suggestion was to use triggers to manage these date fields.
Is there a way to manage the creation of triggers using the E.F./C.F. so that I don't have to re-create them every time my model changes?
ricka6 from the asp.net forums suggested I include the following post as it may be related: Mapping many to many relationship
Thank you!
-Walker
Try using EF 4.3 with database migrations, so your database won't be recreated every time your model changes. Alternatively, you can take a look at this question for ideas how to create custom database initializer.

Add columns to SqlWebEventProvider

In an ASP.NET application, we'd like to use the SqlWebEventProvider to log any Event that occurs during the application lifetime.
The problem is that we think that the table aspnet_WebEvent_Event doesn't provide enough columns and should log more information (we need to keep the Logged user).
I'm aware that this information could be stored in the "Details" column but it wouldn't then be really simple to filter the results and build reports.
So I'm searching for a simple solution to add a column. I wish I could derive SqlWebEventProvider but the methods used to build the stored procedure parameters are private (PrepareParams() and FillParams()).
Any simple solution that doesn't imply to rewrite the entire Provider class ?
Instead of adding columns to the SqlWebEventProvider and it's table default schema, you may consider creating your own WebEventProvider that logs events to a database of your own schema.
Here is an introductory reference on how to do so.
http://bit.ly/2fXeuH
After a lot of searching it seems that it is not possible without inheriting from the existing SqlWebEventProvider and overriding the methods properly to insert the values.
You can look into the .NET Framework code to check for the current implementation with .Net Reflector

Resources