# Tuesday, 07 December 2010

If you are currently invested in LINQ to SQL and want to upgrade to Telerik OpenAccess ORM, with the new OpenAccess Q3 release you can do this quite easily. There is a new wizard included with OpenAccess that will automatically convert your LINQ to SQL classes to Telerik LINQ classes. Let’s take a look.

I’ll start with a simple project that has a simple LINQ to SQL model in it: Northwind.dbml. It is mapped to the Northwind database tables.

image

I created a simple web form that has a GridView on it. I decided that I would try to stump the wizard by writing a complex LINQ statement, one with aggregates, joins, sums, and projections to anonymous types. Then I take that code and bind it to the GridView. The LINQ code is shown here. 

   1:  //DataContext
   2:  NorthwindDataContext dat = new NorthwindDataContext();
   3:  //LINQ Query to Aggergate and Group by to an new type
   4:  var result = from i in
   5:                      (
   6:                      from c in dat.Customers
   7:                      join o in dat.Orders
   8:                      on c.CustomerID equals o.CustomerID
   9:                      select new { c.Country, o.Freight }
  10:                      )
  11:                  group i by new { i.Country } into g
  12:                  select new { g.Key.Country, TotalAmt = g.Sum(f => f.Freight) };
  13:              
  14:  //bind the results
  15:  GridView1.DataSource = result;
  16:  GridView1.DataBind();

Results are shown here:

image

 

Conversion time. Doing the convert is simple and done in place. Just right click on the LINQ to SQL model and choose “Convert From L2S Model to Domain Model” from the context menu.

image

 

This will bring up the OpenAccess Conversion wizard. In reality the wizard is one page. If you accept the defaults, the wizard will create a new RLINQ file (Telerik OpenAccess LINQ file) and give it the same Name and Namespace as the LINQ to SQL model. In addition, it will backup the old files.

image

 

Accepting all of the defaults and clicking next brings you to the confirmation page.

image

 

From here click Finish and the wizard will do its work. You will see a conversion report come up.

 

image

Now you will have a new OpenAccess Domain Model in your project.

image

 

Since your project now has two identically names LINQ classes, it is time to delete the LINQ to SQL class. (Don’t worry it is backed up.) Without changing any code in my application, I press F5 and the project runs, but now using Telerik OpenAccess.

Enjoy!

image

Comments are closed.