# Thursday, 17 June 2010

With the Q1 release of Telerik OpenAccess ORM, Telerik released a brand new LINQ Implementation and supporting Visual Entity Designer. With the upcoming Q2 release next month, we will introduce full WCF RIA Services support. If you want to get started now you can wire up the services yourself pretty easily. Let’s take a look at how to get your feet wet with RIA Services and Telerik’s LINQ implementation.

Before you get started, you will need a few things installed:

  • Visual Studio 2010
  • Silverlight 4
  • WCF RIA Services for Visual Studio 2010
  • Northwind sample database
  • Telerik OpenAccess ORM Q1 Service Pack 1 or higher

Getting Started: The Easy Stuff

Let’s create a new Silverlight application first. In the New Silverlight Application dialog, check the “Enable WCF RIA Services” checkbox. This will enable RIA Services.

image

The next step is to create a new Telerik Domain Model in the server (ASP.NET) project. I have a detailed walk through here on how to do that. We’ll create a new Domain Model by right clicking on the server project and selecting “Add” and choosing the Telerik Domain Model from the menu. Then we will map all of the tables from Northwind using the wizard. We’ll also keep the default model name of NorthwindEntityDiagrams.

image

We’re in good shape. So far if you have used the new LINQ Implementation nothing is new (or LINQ to SQL/EF for that matter.)  Now let’s add the RIA Services stuff.

Housekeeping-Adding References

Since our RIA Services support is still beta, you have to wire up a few things manually, including some references. You need to add:

  • Telerik.OpenAccess.Ria.Extensions.dll (found under “Browse: Program Files|Telerik|OpenAccess ORM|Bin)
  • System.ServiceModel.DomainServices.Server.dll
  • System.ServiceModel.DomainServices.Hosting.dll
  • System.ComponentModel.DataAnnotations.dll

image

Now we are ready to create the domain class.

Creating the Domain Class

Add a new Domain Service Class by right clicking and selecting Add|New Item and choose Domain Service Class.

image

Accept the defaults in the dialog and then we are ready to go. (Note at this time OpenAccess does not support creation of the class for metadata, but will soon, possibly even before Q2.)

image

Once you accept this dialog, a new empty class is generated.

   1:      [EnableClientAccess()]
   2:      public class DomainService1 : DomainService
   3:      {
   4:      }

 

We need to add a using statement so we can make sure our DomainService uses the OpenAccess model: using Telerik.OpenAccess;

Now change the inheritance of DomainService1 to this:

   1:  [EnableClientAccess()]
   2:  public class DomainService1 : OpenAccessDomainService<NorthwindEntityDiagrams>
   3:  {
   4:  }

Now we have one last step to create our DomainService, we have to add the CRUD methods. (In the future all of this will be done automatically for you!)

   1:  {
   2:      public IQueryable<Customer> GetCustomers() 
   3:      { 
   4:          return this.DataContext.Customers; 
   5:      }
   6:   
   7:      public void InsertCustomer(Customer c)
   8:      {
   9:          this.DataContext.Add(c);
  10:          this.DataContext.SaveChanges();
  11:      }
  12:      public void DeleteCustomer(Customer c)
  13:      {
  14:          this.DataContext.Delete(c);
  15:          this.DataContext.SaveChanges();
  16:      }

These are the methods of your DomainService. You can also add business logic here. Let’s do that with our GetCustomers() query.  I will write some business logic that filters all of the customers by the country of Germany. Of course you would have more complex business logic here, however, I just want to demonstrate the point. All clients that use this DomainService will inherit this business logic, even if you expose your service as an OData feed. Our implementation is here:

   1:  public IQueryable<Customer> GetCustomers() 
   2:  { 
   3:      return this.DataContext.Customers
   4:          .Where(c=> c.Country=="Germany")
   5:          .OrderBy(c=> c.CustomerID); 
   6:  }

 

Now you are done. Compile and let’s get cracking on a Silverlight client.

Creating the Silverlight Client

This is the easy part. We’ll use the RIA Services drag and drop features. Open MainPage.XAML in the Silverlight application and in the Data Sources window, drag and drop the Customer entity to the XAML form. (Tip: if the Data Sources window is blank or not showing up, you can manually force it to come up via the “Data” menu option on the main menu in Visual Studio.)

Once you drag and drop the entity to the form, a grid will automatically show up.

image

Now press F5 and see the application running.

image

That's it! We just created an OpenAccess based RIA Services application!

Of course there is a lot more to RIA Services than just binding a grid, however, this demonstration should show you that once you create your DomainService class, all of the RIA Services “stuff” just works for you. In future posts we will look at more RIA Services features as well as creating a query method.

Enjoy!

posted on Thursday, 17 June 2010 09:06:30 (Eastern Daylight Time, UTC-04:00)  #    Comments [3] Trackback
# Wednesday, 16 June 2010

The true power of OData is that the programming model is the same for any feed. I spend a lot of time building and demoing my own feeds- usually building an OData service around Northwind or AdventureWorks. To realize the power of OData you also need to know that you can consume public feeds. Let’s take a look at consuming the Microsoft TechEd Sessions OData Service. The TechEd service can be found here: http://odata.msteched.com/sessions.svc/

Being a RESTful service, we can drill down a little and investigate our data. I will do some URL querying and look at a list of all the speakers as well as their sessions. For example I can drill down to see all speakers named “Forte”

http://odata.msteched.com/sessions.svc/Speakers?$filter=SpeakerLastName eq 'Forte'

Or all of my sessions:

http://odata.msteched.com/sessions.svc/Speakers(1621)/Sessions

This is the beauty of OData, we don’t know how it was created, we also don’t care. All we care is if we can consume it easily. Let’s do so with an ASP.net application and the OData client for ASP.NET.

To get started, create a new ASP.NET application. In the application, right click on the References folder of the project in the Solution Explorer and select “Add Service Reference”. Put in the public URL of the TechED 2010 OData Service. This creates a proxy so you can code against the service locally and not know the difference.

image

Next set a reference to System.Data.Services.Client. This will enable us to use the OData client library and LINQ on the ASP.net client. Then drag a textbox, button, and a gridview to the ASP page. We’ll fill the gridView with the Speaker data filtered on the last name field based on what was typed in to the textbox. We accomplish this with the following code on the button click.

   1:  //set a reference to ServiceReference1 and System.Data.Services.Client
   2:  ODataTENA10Entities dat = 
   3:      new ODataTENA10Entities(new Uri("http://odata.msteched.com/sessions.svc/"));
   4:              
   5:  //LINQ statement to filter by the textbox
   6:  var result = from s in dat.Speakers
   7:                  where s.SpeakerLastName.StartsWith(TextBox1.Text.ToString())
   8:                  orderby s.SpeakerLastName
   9:                  select s; 
  10:   
  11:  //bind the results
  12:  GridView1.DataSource = result;
  13:  GridView1.DataBind();

 

Line 2 and 3 sets the data context and the LINQ statement is on lines 6-9. Line 7 is where we do the filtering based on the textbox. Pretty easy stuff.

image

Enjoy!

posted on Wednesday, 16 June 2010 07:19:13 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Tuesday, 15 June 2010

Last month I participated in a World Cup themed skit about information worker productivity at the launch of Office 2010 and SharePoint 2010 in Hong Kong. You can watch the skits here. It was a lot of fun and shows off a ton of new features in Office and Sharepoint, including PowerPivot.

Enjoy!

posted on Tuesday, 15 June 2010 04:56:51 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Monday, 14 June 2010

Last week at TechEd North America I did DEV303, Building RESTful Applications with the OData Protocol. I really enjoy doing this session since I get to code on the fly and talk about building applications. At a high level we covered:

  • What is REST, comparison to Web Services (REST is resource based, Web Services is RPC/method based)
  • What is OData, who is using it
  • When to use OData vs RIA Services (OData is for exposing data as a service across boundaries, RIA is for a VB6 style RAD application development)
  • Using WCF Data Services to build an OData Service
  • Consuming the WCF Data Service in Silverlight asynchronously –yes everyone had to suffer and watch me code
  • A Bill Gates joke
  • WCF Data Services Service Operations, Data Interceptors (Query and Change), Data paging
  • Consuming OData Services in ASP.NET (select and add, we even got to see my custom error raise)

You can download the slides and code here.

posted on Monday, 14 June 2010 20:25:55 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Thursday, 10 June 2010

Telerik won the “Best of TechEd” award in the “Best Components and Middleware” category last night at TechEd in New Orleans, LA. Our premium collection was judged as the most innovative and best value over all the other vendors.

All 200+ of the Telerik employees around the world feel honored and those of us here of course took time to celebrate on Bourbon street. Now we’re back to work and hope to live up to our customers high expectations. (If you are still at TechEd, swing by the booth and take a look at the award, we are here until 3pm today when the Expo closes.)

Thanks again to all of our customers, you make us better and we do it for you.

31691_1451994147381_1459091054_31166546_61564_n

Here are the Telerikers left standing late last night in the French Quarter in New Orleans.

posted on Thursday, 10 June 2010 12:34:20 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Tuesday, 08 June 2010

Thursday, June 17, 2010
10 Practices Every Developer Should Start Right Now

Subject: 
You must register at https://www.clicktoattend.com/invitation.aspx?code=149217 in order to be admitted to the building and attend.
Based on Caleb’s popular blog series, these are the 10 things that if you or your company starting doing today, it would drastically change the way that you write and deliver software!
Topics hit on: Object Oriented Principals, SOLID Coding, Security Concerns, Software Patterns, Automated Testing, Source Control - Branching and Merging Strategies, Continuous Integration, Agile | Scrum | XP | Lean, Team Dynamics, Continually Learning

Speaker: 
Caleb Jenkins, Proaction Mentors
As a long time community leader and former Microsoft Developer Evangelist Caleb is well known for his engaging speaking style, depth of knowledge and creative energy. Caleb is the Principal Mentor and founder of Proaction Mentors - a Software Architecture and Development Mentoring Company.
Working as a Microsoft Certified Solution Developer, Certified Trainer and .Net Architect Caleb has helped to design and implement enterprise .Net solutions for some of the largest companies in the world; Six Flags, Countrywide Mortgage, American Airlines, CGI-AMS, Dollar Thrifty Automotive Group and Sunoco Inc. to name a few.
You may also recognize Caleb from his previous work with Improving Enterprises, or from his work as an active national speaker for the International .NET Association (INETA), a Microsoft MVP for ASP.NET, a Certified Scrum Master. He’s worked as a technical editor for Wrox Press, and was recently a featured presenter on xTrain and Adobe.TV. Caleb is also the host, cameraman and editor for CommunityCast TV (CommunityCast.wordpress.com).

Date: 
Thursday, June 17, 2010

Time: 
Reception 6:00 PM , Program 6:30 PM

Location:  
Microsoft , 1290 Avenue of the Americas (the AXA building - bet. 51st/52nd Sts.) , 6th floor

Directions:
B/D/F/V to 47th-50th Sts./Rockefeller Ctr
1 to 50th St./Bway
N/R/W to 49th St./7th Ave.

posted on Tuesday, 08 June 2010 07:54:32 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Monday, 07 June 2010

Yesterday Joel and I did the day long Agile precon at TechEd in New Orleans, LA. We had a great crowd and were able to keep them engaged for 8 hours. You can download the materials here.

We used an “Agile presenting” technique where we put the agenda in an “Agenda Backlog” and we reprioritized after every sprint (agenda item) and let the audience decide what we would talk about next. To our surprise the audience voted against two planned sections and we did two new sections on the fly. We talked about:

  • Agile theory and agile methodologies (XP, Scrum, FDD, DSDM, *DD, Kanban, etc)
  • Intro to Scrum
  • Agile Estimation
  • Challenges to Implementing Agile in General
  • Challenges to Implementing Agile: In the Enterprise
  • Challenges to Implementing Agile: Remote Teams
  • Tools
  • QA and Documentation

We got into a discussion on what happens when the team finishes early, do you stop the sprint, or give them more work to do. (Joel and I both go against the agile literature and give the team more work!)

We also took a few micro-breaks to rest our brain to talk about the iPhone v Android, how I buy Joel clothes, and movie quotes from the Matrix (I know Kung Fu) and What about Bob (Baby Steps).

We also recommended a book, one of my favorite management books of all time: Peopleware. For those of you non-techies reading this blog (I don’t know why!) if you manage teams, this book is also for you.

Hope to do this seminar again soon!

posted on Monday, 07 June 2010 12:04:51 (Eastern Daylight Time, UTC-04:00)  #    Comments [1] Trackback
# Friday, 04 June 2010

While connecting flights in Japan today en route to TechEd, the security wanted to re-run my bag. They kinda freaked out as to what was in it. They took everything out that was electronic and ran it again. The electronics took three bins, here is what it was:

  • Dell laptop
  • Laptop plug
  • Adapter (my plug uses Hong Kong prongs)
  • Cat5 wire
  • USB external hard drive
  • Wireless mouse
  • Kindle
  • Kindle wire
  • Bose noise cancellation headphones
  • Zune
  • Zune wire
  • Canon G10 Camera
  • Camera battery charger
  • Camera wire
  • Android Nexus One Phone
  • Charger

By now the only thing left in the bag was my notebook, business cards, a pen, and my passport. I would have taken a photo but they had my camera!

posted on Friday, 04 June 2010 06:31:17 (Eastern Daylight Time, UTC-04:00)  #    Comments [1] Trackback
# Thursday, 03 June 2010

Last week Telerik released a service pack for OpenAccess Q1. The service pack fixes a few issues with Telerik’s new LINQ implementation working under Visual Studio 2010. In addition, the service pack shipped the Data Services Wizard; the Data Service Wizard is no longer a separate install. You can use the Data Service Wizard with traditional OpenAccess classes or the new LINQ implementation. Today I will show show you a new feature of the wizard: automatically creating a styled Silverlight application from your domain model. Future blog posts will show how to use RIA Services as well as SQL Azure.

To get started open up Visual Studio 2010 and create a new ASP.net application. Create a new domain model by right clicking on the project and say Add|New Item and choose Telerik OpenAccess Domain Model from the dialog.

image

This will bring up the OpenAccess ORM Data Wizard to create your domain model by mapping tables to entities. Let’s use Northwind and map all tables and use the default model name: NorthwindEntityDiagrams. While there are other advanced features of the wizard, like T4 templates to override the default codegen, let’s just accept the defaults and finish.

image

Once you click Finish the wizard will add a new domain model to your project.

image

Now that we have our domain model, it is time to run the Data Services Wizard to automatically create the a RESTful service using WCF Data Services. (The data service wizard also gives us the ability to create a WCF endpoint as well.) This can be done from the Telerik|Data Services Wizard menu option from the Visual Studio main menu (or right clicking on the EntityDiagrams1.rlinq file.) The first page of the wizard asks you where the domain model lives and what project to place the new service in. We’ll do it all in the same project.

image

The next page of the wizard asks you what entities you want to expose in your service as well as if you want to generate a Silverlight Application. If you check this you are given the option to use the standard Microsoft Silverlight controls or the Telerik controls (if you have them installed.) If you choose the Telerik controls, you will also be able to choose a theme for your Silverlight application. The drop down will show you a list of all of the installed themes. I’ll go ahead and choose the Windows7 theme.

image

After you click through the finish page of the wizard, the next step is to hit F5 and run your application. A basic, but styled, Silverlight application is created for you, getting you started with all of the CRUD methods. The Telerik version has all of the features your would expect, built in sorting and filtering, grouping, etc. I know that you will want to change the baseline application, but this is a great start, eliminating all of the asynchronous CRUD code that you have to write. Not bad for about 30 seconds of work!

image

Enjoy!

posted on Thursday, 03 June 2010 03:41:03 (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback