DLinq - Microsoft O/R Mapper for .NET 2.0 - ObjectSpaces to DLinq

DLinq is Microsoft's O/R Mapper for .NET 2.0.  ObjectSpaces as we know it is gone, and Microsoft has released a preview of DLinq - a solution for those developers looking to work with relational data in an object-oriented fashion.

DLinq is part of the Linq Project.  LINQ stands for “Language Integrated QUery.” LINQ fundamentally is about integrating query operations into the .NET platform in a comprehensive and open manner. It’s also about providing a unified way for you to query across any kind of data that you have in your program, whether it’s relational, objects or XML.

 

DLinq Entities and Attributes

DLinq uses attributes on entities to provide a data map of the relationship between the entity in your application and the table it maps to in the relational database.  Here is an example of the attributes shown on an entity:

[Table(Name="Customers")]
public class Customer
{
    [Column(Id=true)]
    public string CustomerID;
    [Column]
    public string City;
}

The Customer class maps to a table, called Customers, in the database. The public fields, CustomerID and City, map to 2 columns in the Customers table, also called CustomerID and City.  The CustomerID is the primary key for the table, so Id=true identifies it as such.

 

DLinq DataContext

DLinq uses a DataContext Object that is similar to an ADO.NET Connection object.  It is essentially the pipeline for all communication to the database.  Setting up a connection string and then querying for all Customers that are located in London is as simple as follows:

public partial class Northwind : DataContext
{
    public Table<Customer> Customers;
    public Table<Order> Orders;
    public Northwind(string connection): base(connection) {}
}

Northwind db = new Northwind("c:\\northwind\\northwnd.mdf");
var q =
    from c in db.Customers
    where c.City == "London"
    select c;
foreach (var cust in q)
    Console.WriteLine("id = {0}, City = {1}",
    cust.CustomerID, cust.City);

 

O/R Mapping With Attributes

According to several O/R Mapper vendors / developers, using attributes to map class fields and properties to table columns doesn't scale well.

I don't have any concrete data on this subject, so I can't offer an opinion of whether DLinq will scale well on projects.  Personally, I would hold off on passing judgement on DLinq until it at least gets in a beta stage.  If nothing else, it certainly looks like it will rock on small projects, which is great for those developers that build applications for small business, online home business, etc.  I would hold off on concerns about scalability until the product has time to mature, Microsoft has full opportunity to address such claims, and better yet, you check it out yourself.

I do know that attribute-based O/R Mappers are not new, so you can experience one right now for yourself in .NET 1.1 using Gentle.NET, Retina.NET, or eXpress Persistent Objects (XPO) to name a few.  Of course, you won't get the cool query language offered by LINQ, but you can get your feet wet with attribute-based O/R Mapping to see if it makes sense for you.

 

DLinq Resources

 

O/R Mapper and Code Generation Resources

 

posted on Thursday, September 15, 2005 11:57 AM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices