Saturday, May 29, 2010

Exposing Data using OData protocol and Consuming it using Excel [Power Pivot]

 

MS Renamed  ADO.NET Data Service => WCF Data Service this service exposed using OData Protocol  OData means Open Data protocol . here is the some of the MS products uses this OData including: SharePoint 2010 (Lists), SQL Server 2008 R2, PowerPivot, Windows Azure Table Storage

First Create ASP.NET Empty Web application project.

image

Now we need to add or create our Model Here i am going to use LINQ to SQL. We can use ADO.NET Entity Data Model as well. Now Select LINQ to SQL Classes template and add to our ASP.NET project. LINQ To SQL Template provides Designer surface where you can drag and drop the DB tables which you wanted to expose as WCF Data Services ( OData).

image

Once Model is created next we need to WCF Data Service template to our project.

image

Next we need to open WCFdataService1.cs file and Add our LINQ TO SQL DataContext class  and Edit the SetEinittySetAccessRule config .

Here i wanted to expose all the Entity so i provided *.

image

Now compile the project and Browse the .SVC

image

Here below query shows how to access all the records from Departments.

image

Now we have successfully exposed our WCF Data Service (OData) . Next we will consume this Data service from Excel using Power Pivot Add-in. first we need to download Power Pivot and install.

Now fire up Excel 2010 you will see Power Pivot Ribbon tab click that.

image

Next Click Power Pivot window and click From Data Feeds ( Our services expose Atom pub)

image

Next Edit friendly name for your Data Feed and provide the Data Feed URL in my case the service is Hosted and running in my local box so my URL will be http://localhost:61411/WcfDataService1.svc. to verify the service is running  you can click Test Connection button and check.

image

Once you have done that then click next . at this point Excel power pivot connects  service  and gets all Data.

image

Next select the Tables you wanted to import and click Finish .

image

Here is the final result .it tells how may rows are in each tables.

image

Now we have all the Data in Excel . Since most of them knows how to work on excel  they can do all BI related stuff.

image

You can do all Filter , sorting etc…

Nandri(Thanks)

Sreenivasaragavan.

Friday, May 28, 2010

MVVM –Model-View-ViewModel Design Pattern

 

Design Patterns: In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. A design pattern isn't a finished design that can be transformed directly into code. It is a description or template for how to solve a problem that can be used in many different situations.

What is MVVM?

It’s an architectural pattern created by John Gossman from WPF team.

MVVM is Model-View-ViewModel Design pattern .But this is different from Common Design pattern which is created by GOF (Gang  Of Four) The four authors were Erich Gamma, Richard Helm, Ralph Johnson and John Vlissides

Model => Holds the Data.

View => Presents/Shows the Data.

ViewModel =>Holds the Models which is Presented/Showed in a View. 

When we are building WPF or Silverlight applications is better to use MVVM pattern because this pattern offers the following benefits.

 

  1. Testability ( ViewModel is easier to unit test than code-behind or event driven code)
  2. Clear separation between UX designer and developer
  3. Increases the "Blend ability" of your view
  4. Model never needs to be changed to support changes to the view
  5. ViewModel rarely needs to be changed to support changes to the view
  6. No duplicated code to update views

The Important is  MVVM  makes uses of  Silverlight & WPF Binding.

image

Here I am going to show how to use MVVM pattern when building Silverlight application. Here i am not going to use any framework tooling. Here is the workflow I am going to follow.

  1. Create a Silverlight Application.
  2. Create Model, View,ViewModel Folders.
  3. Add or Create a Model class with some properties . Here I am going to create Custom class. ( we can use EF , WCF  etc..).
  4. Implements INotifyPropertyChanged Interface.
  5. Create ViewModelBase and ViewModel Classes.
  6. Create a View.
  7. Do the Binding.

First Fire up VS.NET 2010 and Create a Silverlight Application Project.

image 

Once project is created now we need to add the following  Model , View , ViewModel folders as shown below.

image

Now we need to create Model. To do that right click on Model Folder and Add the class called UserProfile and add the following public properties as shown below.

image 

Now right click on ViewModel folder and add the following classes.

This viewModelbase class just implements the INotifyPropertyChanged Interface this way both source and Target objects are in Sync.

image

The ObservableCollection class automatically implements  INotifyPropertyChanged Interface.

image

Now right click on View Folder and add the Silverlight Usercontrol name it as UserProfileView.XAML And add the following XAML code

image

And add the following code in the UserProfileView.XAML code behind.

image

Here i am creating 100 user profiles and adding to ObervableCollection and setting to UserProfileViewModel class and setting Datacontext.

image

image

I hope i explained MVVM pattern very simple and everyone can understand easily . Here i used Properties binding even we can use ICommand as well  (Silverlight 4.0). I am happy to answer this blog readers questions.

Nandri(Thanks)

SreenivasaRagavan.

Thursday, May 27, 2010

My Article Published on DIWUG SharePoint Magazine.

 

Please download the second issue of SharePoint eMagazine. @ http://information-worker.org/freemagazine.aspx

My Article Title is Incorporating External Data in SharePoint 2010 using WCF - Raghavan Ramadurai

image

Nandri(Thanks)

SreenivasaRagavan.

Printing In Silverlight 4.0

In silverlight 4.0 the main API for printing is PrintDocument class which lives in System.Windows.Printing namespace. Here are the steps we need to do  for a Printing.

1) First Create instance of  PrintDocument class.

2) Next Implement the PrintPage event handler and  Set PageVisual to the UIElement you want to print.

3)  Finally call Print() method.

This is very easy way to print this is same as screen printing.

let see in action

First Create Silverlight application project.

image 

In the Next Dialog box we just say click OK .

image

now lets add some XAML code to build UI with some Text and try to print them.

image

Here is my GUI with some sample Contact Lists.

image

 

   Event handler to handle Printpage event.

     Here i am  using Lambda Expression (C# 3.0)  basically the down rectangle code replaced by the above Rectangle  Lambda Expression.

image

image

Nandri(Thanks)

SreenivasaRagavan.

Thursday, May 20, 2010

Developing Master/Details Application In SilverLight

In this Blog post I am going to show how to create a Silverlight application Master/Details Records display. First Open of the VS.NET 2010 and create Silverlight application project.

Creating a SilverLight Application Project

image

     In this application we are going to use WCF RIA services to bring Data from Backend so we need to check the  Enable WCF RIA Services Check-Box. and then click ok.

Enabling WCF RIA Services

 

image[52]

At this point VS.NET will created two projects.  One is Silverlight Client application project and another one Web application project as shown below.

image

Adding EF Model

Now we need to add Data Model to our project. Here we can use either LINQ TO SQL or EF. But I am going to use  EF Data Model Template. so let us add  ADO.NET Enitity Data Model template to this project and follow the Wizard.

image

   Here I am going to use Chinook Sample Database which you can download from CodePlex. Next we are going to select an option Generate From Database and create the EF Model.

image

Once EF Model created successfully at this point we need to compile or build our project so that VS.NET will get latest changes or additions that we made  in our solution. This build process helps to choose Entities when we are creating Domain Service. 

Adding Domain Service Class

Now we need to add Domain Service template to our project to create WCF RIA Service. Here we asked to select the Entities which we wanted to exposes to client side and can perform CURD operations . having said that Here I am selecting all Entities and also enabling editing option as shown below. And do not forgot to check the options which will Generate metadata for our EF classes.  

image

image

   Now once again we need to compile or build the project at this point VS.NET generate DomainContext and Entities on client side. (WCF RIA Service tool magic).

  Here we need to add some UI to display Customer and their Invoices. To do click on Data Sources and right click on Customer and select DataGrid and drag and drop it on  Mainpage.xmal Designer surface. do the same steps for Invoices as well.  At this point we have two Datagird. Here whenever user select customer Record we need to display related invoices in another DataGrid called Customer Invoices.

Creating UI

 

image

 

  Adding [Include Attribute]

     To bring right data from backend we need to modify our Entity Metadata class as shown below.

 

image

 

      Here I have added another method which will returns both Customer and their invoices records .

image

 

  Now build the project and Run . Now if we select a record or row in Customer DataGrid the related invoices records are displayed  in Customer Invoices datagrid.

image

Next blog post will see how to Add Busy Indicator when loading Data, Sorting and Grouping of the Data.

Nandri(Thanks)

SreenivasaRagavan.

Tuesday, May 18, 2010

Building SilverLight Application using WCF RIA Services.

 

WCF RIA Services.

In Silverlight project you can turn on WCF RIA Services Link. This WCF RIA Services link connects Silverlight client Application and Web Project.

image

WCR RIA Service simplify the N-tier development and it allow to share Data model, Validation Rules and other Data annotations across tiers. what ever methods or Entities which are add in Server Side its replicates to client side application this makes easy access to server side entities. We Add Domain Service class to expose WCF RIA Service on Server side. When you compile the project it automatically creates corresponding Domain Context class in client application this Class helps to tracking changes and CURD operations of Entities.

Here I am going to build Simple Application which uses WCF RIA Services.

1) Fire up VS.NET 2010 and Create SilverLight Business Application.

image

  This project Creates two application one is Silverlight client project and web project as shown below. This to projects connected or Linked using WCF RIA Services. 

image

image

Now I am going to add  EF model from one of the sample Database which you can download from CodePlex.

image

      Now follow the Wizard.

      Next we are going to select Generate From Database options. Here we are going to generate our model from Existing Database. 

image

   Select Database which you wanted to use here I am going to use Chinook Sample DB.

image

     Here we need to select the Tables which you wanted to add to our EF Model. Here I am going to select Customer and Employee Tables.

image

Now we have created our model. At this point we need to compile our project so that Silverlight application will know the new changes to our solutions. Now we need to Add Domain Service Class.

  image

  Please make sure that next step you check the checkboxes as shown below. Here I am enabling Editing options for both Customer and Employee entities.

image

Now we can start  building UI to display Customer records on client side. Now select Data Source and click and select DataGrid then Drag and Drop Customer To UI Design Surface.

image 

At this point VS.NET created Domain Data Source control. as shown below.

image[71]
Now runt the application you will see customer Details displayed in Data Grid as shown below.

image

Nandri(Thanks)

SreenivasaRagavan.