Over a million developers have joined DZone.

Convert an Existing LINQ to SQL Model to Telerik OpenAccess in 30 Seconds

· Database Zone

To stay on top of the changing nature of the data connectivity world and to help enterprises navigate these changes, download this whitepaper from Progress Data Direct that explores the results of the 2016 Data Connectivity Outlook survey.

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. 

//DataContext
NorthwindDataContext dat = new NorthwindDataContext();
//LINQ Query to Aggergate and Group by to an new type
var result = from i in
(
from c in dat.Customers
join o in dat.Orders
on c.CustomerID equals o.CustomerID
select new { c.Country, o.Freight }
)
group i by new { i.Country } into g
select new { g.Key.Country, TotalAmt = g.Sum(f => f.Freight) };

//bind the results
GridView1.DataSource = result;
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

Turn Data Into a Powerful Asset, Not an Obstacle with Democratize Your Data, a Progress Data Direct whitepaper that explains how to provide data access for your users anywhere, anytime and from any source.

Topics:

Published at DZone with permission of Stephen Forte, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}