# Thursday, March 11, 2010

Love LINQ to SQL but are concerned that it is a second class citizen? Need to connect to more databases other than SQL Server? Think that the Entity Framework is too complex? Want a domain model designer for data access that is easy, yet powerful? Then the Telerik Visual Entity Designer is for you.

Built on top of Telerik OpenAccess ORM, a very mature and robust product, Telerik’s Visual Entity Designer is a new way to build your domain model that is very powerful and also real easy to use. How easy? I’ll show you here.

First Look: Using the Telerik Visual Entity Designer

To get started, you need to install the Telerik OpenAccess ORM Q1 release for Visual Studio 2008 or 2010. You don’t need to use any of the Telerik OpenAccess wizards, designers, or using statements. Just right click on your project and select Add|New Item from the context menu. Choose “Telerik OpenAccess Domain Model” from the Visual Studio project templates.


(Note to existing OpenAccess users, don’t run the “Enable ORM” wizard or any other OpenAccess menu unless you are building OpenAccess Entities.)

You will then have to specify the database backend (SQL Server, SQL Azure, Oracle, MySQL, etc) and connection.


After you establish your connection, select the database objects you want to add to your domain model. You can also name your model, by default it will be NameofyourdatabaseEntityDiagrams.


You can click finish here if you are comfortable, or tweak some advanced settings. Many users of domain models like to add prefixes and suffixes to classes, fields, and properties as well as handle pluralization. I personally accept the defaults, however, I hate how DBAs force underscores on me, so I click on the option to remove them.


You can also tweak your namespace, mapping options, and define your own code generation template to gain further control over the outputted code. This is a very powerful feature, but for now, I will just accept the defaults.


When we click finish, you can see your domain model as a file with the .rlinq extension in the Solution Explorer.


You can also bring up the visual designer to view or further tweak your model by double clicking on the model in the Solution Explorer. 


Time to use the model!

Writing a LINQ Query

Programming against the domain model is very simple using LINQ. Just set a reference to the model (line 12 of the code below) and write a standard LINQ statement (lines 14-16).  (OpenAccess users: notice the you don’t need any using statements for OpenAccess or an IObjectScope, just raw LINQ against your model.)

   1:  using System;
   2:  using System.Linq;
   3:  //no need for an OpenAccess using statement
   5:  namespace ConsoleApplication3
   6:  {
   7:      class Program
   8:      {
   9:          static void Main(string[] args)
  10:          {
  11:              //a reference to the data context
  12:              NorthwindEntityDiagrams dat = new NorthwindEntityDiagrams();
  13:              //LINQ Statement
  14:              var result = from c in dat.Customers
  15:                           where c.Country == "Germany"
  16:                           select c;
  18:              //Print out the company name
  19:              foreach (var cust in result)
  20:              {
  21:                  Console.WriteLine("Company Name: " + cust.CompanyName);
  22:              }
  23:              //keep the console window open
  24:              Console.Read();
  25:          }
  26:      }
  27:  }

Lines 19-24 loop through the result of our LINQ query and displays the results.


That’s it! All of the super powerful features of OpenAccess are available to you to further enhance your experience, however, in most cases this is all you need.

In future posts I will show how to use the Visual Designer with some other scenarios. Stay tuned.


Technorati Tags: ,,

Bookmark and Share
posted on Thursday, March 11, 2010 9:26:16 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] Trackback
Related posts:
Mobile Apps Are Dead!
AcceleratorHK Demo Day Videos are Live!
AcceleratorHK Cohort 2 Demo Day!
AcceleratorHK Cohort 2 Week 13: Crunch Time!
AcceleratorHK Cohort 2 Week 12
AcceleratorHK Cohort 2 Week 11: Prototype Day 2!
Tracked by:
"Using Telerik’s new LINQ implementation to create OData data feeds" (Stephen Fo... [Trackback]
"http://www.stephenforte.net/PermaLink,guid,b7c19fd7-2f31-445c-bec9-4b2a1bd3b6f4... [Pingback]
"Social comments and analytics for this post" (uberVU - social comments) [Trackback]
"Telerik Releases the Data Service Wizard" (Stephen Forte`s Blog) [Trackback]
"http://www.stephenforte.net/PermaLink,guid,d7065244-dbc4-4b7d-90d9-a9e02ea20420... [Pingback]
"30 seconds from File|New to a new CRUD Silverlight Application with Telerik’s n... [Trackback]
"http://www.stephenforte.net/PermaLink,guid,c09af762-903a-4b7c-9fba-22e407d4c8a1... [Pingback]
"Using Telerik’s new LINQ implementation with WCF RIA Services: Part I" (Stephen... [Trackback]
"http://www.stephenforte.net/PermaLink,guid,6c2ec0e6-3b89-41f4-b978-0231c711027a... [Pingback]
"Using Telerik’s new LINQ implementation with WCF RIA Services Part II: Query Me... [Trackback]
"http://www.stephenforte.net/PermaLink,guid,dfd5b5f3-e931-4e17-a8f3-b39cf03eea18... [Pingback]
"New goodies in the Q2 Release of Telerik OpenAccess : Part I" (Stephen Forte`s ... [Trackback]
"http://www.stephenforte.net/PermaLink,guid,7cd2d848-8f54-4714-b465-21525235aab7... [Pingback]
"Mocking LINQ to SQL [Continued…] using RLINQ" (Mehfuz's WebLog) [Trackback]
"Mocking LINQ to SQL [Continued…] using RLINQ" (Mehfuz's Log) [Trackback]
"http://www.msdnbangladesh.net/blogs/mvps/archive/2010/07/29/mocking-linq-to-sql... [Pingback]
"http://weblogs.asp.net/mehfuzh/archive/2010/07/29/mocking-linq-to-sql-continued... [Pingback]
Comments are closed.