Connected, Disconnected and DLinq

Here is another FAQ question that has come up at PDC.

Since DLinq is a part of the next version of ADO.NET, it is natural to ask - is it connected or disconnected? After all, we have talked about connected vs disconnected components in ADO.NET quite a bit. DataReader is connected (you are using the underlying connection while consuming the data) while DataSet is disconnected. You need to use DataAdapter to bridge the two worlds. All nice and explicit.

Quite often you need to combine the two modes (as developers do with the DataAdapter + DataSet combo). Wouldn't it be nice if the data access library knew how to provide the benefits of disconnected mode while connecting as and when needed? You would not have the old ADO problems of scalability that ADO.NET solved and yet you would not have to wire all the components explicitly and do all the plumbing yourself. Well DLinq does exactly that. Here is my demo example decorated with comments

class Driver
{

   static void Main(string[] args)
   {

      Northwind db = 
         new Northwind(@"c:\Northwind\Northwnd.mdf"
);

      db.Log = Console.Out;

      int x =3;

      var query = from p in db.Products
                  where
p.SupplierID == x
                  orderby
p.UnitsInStock
            
      select p;

      // No SQL execution up to this point. 
      // The following line will cause a SqlConnection.Open() and SQL query executtion
      Product sauce = query.First();

      sauce.UnitsInStock += 10;

      // No SQL execution up to this point. Connection resource is not used.
      // The following line will cause SqlConnection to be opened again & a SQL update command execution
      db.SubmitChanges();

   }
}

 The use of connections and SQL command execution is essentially driven by the deferred execution (or lazy eval for the functional language folks) in LINQ.

Published 16 September 05 01:53 by Dinesh.Kulkarni

Comments

# Chiranjib Basu said on September 20, 2005 8:28 AM:
Couple of queries i have.

1. No direct way to handle many to many relations.
For example I could not find a direct way to load roles for a given user if
User(1)->(n)UserRole(n)<-(1)Role
2. I have seen few(?) times the query optimizer picks up wrong join strategy, which can be overidden by query hints. How can I do that in DLink? I do not want to call execute?? function on the DataContext with an SQL query.
3. Talking about disconnected mode of operation of the business entities I would like to know how sate management is handled in the following scenareo. My client calls a WS that gives me an entity. I make some changes and submit back to the WS. How does DLinq handle optimistic locking in such case?
4. Does Dataset fit in the scheme of things in DLinq.

Answers will be greatly appreciated.

Thanks.
# Hoang Cung said on September 20, 2005 10:19 AM:
Where is the ad-hoc query generated from the update command (SubmitChanges) and could it be intercepted
# Darryl T. Agostinelli on Software said on April 4, 2006 11:09 AM:
Linq uses C# Extension methodshttp://bloggingabout.net/blogs/olaf/archive/2005/09/18/9469.aspx
Linq...
# Dinesh s Cyberstation Connected Disconnected and DLinq | Indoor Grills said on June 1, 2009 3:36 PM:

PingBack from http://indoorgrillsrecipes.info/story.php?id=5327

New Comments to this post are disabled

About Dinesh.Kulkarni

I am a program manager in the Visual C# Product Unit of Microsoft. I am currently working on the LINQ project with specific responsibility for DLinq. Previously, I have been in a PM in SQL Server working on ObjectSpaces and DataSet. In pre-MS life, I have worked for companies ranging from startup to IBM on a wide range of software projects. Before I started working, I did M.S.E.E. and Ph.D. (CSE) from the University of Notre Dame and B.Tech. E.E. from IIT Bombay, India.

Search

This Blog

Syndication

Page view tracker