Sunday, September 21, 2008

Dynamic Data Web Application with ASP.NET 3.5

Just saw VTD [ Virtual Tech Days ] sessions..man..Microsoft is coming with a boom. Loads of new stuffs and frameworks getting added day after day.Really a confusion state sometime to learn and implement simply because each one is unique and dependent on something, so no option but is to learn.

Well, I spend whole day with Dynamic Data today [ This was so exciting that I forget to have coffee in afternoon ;-) ]

First you need to understand What is Dynamic Data??, well answer you can get on asp.net site and some other forums or even on wiki. What you need to do it and learn it is to have .NET framework 3.5 SP and Visual Studio 2008 SP installed on your machine, VS08 SP do comes with .net 3.5 SP, so relax and just do this one installation. This will add Dynamic Data Site template along with another hot technology Entitiy Framework.

OpenTemplate

You need to select Dynamic Data Web Application since Dynamic Data Entities Web Application belongs to ADO.NET Entity framework and what we are doing is to implement it with LINQ to SQL. Once you create new site, you will have following structure which is quite big and confusing for first time.

SolutionExplorer

You can see lots of folders are there, out of which we are mostly doing things with “Field Templates” and “Page Templates”, Filed Templates provided to have different data types and Page Templates are provided to have all the necessary functions on data like Gird and Detail view to do DML operations on data which is getting from LINQ to SQL.

Now next step is to implement LINQ To SQL, So add a new context to your project just like you do in day to day LINQ to SQL.

LINQtoSQL

I will now add NorthwindDataContext to my project and simply drag and drop the tables on page which I want, similar as we do in LINQ to SQL. Then once we done with that then the real thing of Dynamic Data starts, First go to Global.asax file and do modifications in that like passing the correct Contextname etc.

Globalasax

we need to write following code there as :

model.RegisterContext(typeof(NorthWindDataContextDataContext),new ContextConfiguration()

{ScaffoldAllTables = true});

You can read more about MetaModel on MSDN, here we are creating instance of MetaModel. Else what ever routing part is there with other config. that I will share in my upcoming article on Dynamic Data.

Now simply Run the application, I have done rather I tried my best to edit some of its core design, soon i will implement my own CSS to Grid etc. but first output will be list of tables in that particular context.I added few lables to it and binded with count of tables from that particular context.

defaulttablecount

Once you select particular Table you will be then thrown to Grid layout :

op2

You can see the Grid with built-in Templates for Edit,Delete and Details view along with Pagination.

Typical Edit Mode :

EditRecord

So, you can Edit and Update the same or even you can delete reocords too, You too have facility to insert records that too with Validations, you have <asp:DynamicValidator> control got introduce which is especially for Dynamic Data and it do work like normal validation controls we have normally. so its only for specific purpose. So this is how all the DML is getting managed automatically in Dynamic Data without writing much of code. this is unique to build rapid web applications with less time span spending on development.

 InsertWithValidation

Well.This is all about Dynamic Data, you are ready with your first application on Dynamic Data using ASP.NET 3.5, I will soon come with more information on this,but this will be a good healthy start for us to move ahead in Dynamic Data Web Application arena.

One more thing, before ending this article is that if you by chance have made ScaffoldAllTables = false in Global.asax file.

TableCountScaffoldException

Second block shows the throw where the error will get thrown if  ScaffoldAllTables attribute is false, so make it true and run the application, Also first block is showing how i added table count to this application.

So this is how one can go ahead and build rich Dynamic Data Web Application within no time. I will soon be here with more Dynamic Data related information.

Vikram.

5 comments:

Unknown said...

Hello Vikram,

Thanks for the Information that you have shared. It's really great feature. I would implement in my project.

Regards,
Amit

Vikram Pendse said...

Thanks Amit, Soon I will post out more things on the same.

Hemant Savkar said...

Hi Vikram,
It nice that we have such features in ASP.NET 3.5 ,now in my scenario i am working on the SOA environment where i only have to Consume the web services from the Proxies.In my Scenarion is it possible to use the LINQ only.Please post any Project or Article if you have

Thanks
Hemant

Ashwini said...

Hi Vikram ,

Thanks for information,
But i have 1 doubt,
if i dont want scaffolding (templates) for all tables in the model , then how to disable it ?

Thanks in advance,
Ashwini

Ashwini said...

Hi Vikram,

I dont want to create scaffolding for all tables in the model. How to disable it?

Thanks in advance

Ashwini