11 June 2010

DLinq and XLinq

Hmmm. What can I say here? do not get afraid on these names.We have already seen what is LINQ and also  seen some code samples how LINQ can help .net developers who believed that Object Relational Mapping is a key to application development.LINQ is to .net what Hibernate is to Java. LINQ goes a few steps ahead and facilitates querying not only SQL databases, but also XML, objects, etc. For developing any application you need not search for any developers who are good in SQL rather you can search for .net developers.Ok now let us look in to this terms-LINQ,DLinq,XLinq:
The Linq project offers querying features integrated right into programming languages. This will allow executing strongly-typed queries on sources such as databases, XML documents or even object graphs in memory. This technology relies on innovations on programming languages like C# 3.
DLinq is an extension to Linq that allows querying a database (only SQL Server for the moment) and do object-relational mapping.
XLinq is an extension to Linq that allows querying XML documents, as well as creating or transforming XML.To make it more clear lets take the example from previous blog, take the business object customer



public class Customer
{
  public string CustomerID;
  public string Name;
}

Well, decorate it with a  few attributes and you get this.(This was nothing which done by the visual studio behind the seen of generating data context class in our last example) 
[Table(Name="Customers")]
public class Customer

{
  [Column(Id=true)]
  public string CustomerID;
  [Column]
  public string Name;
}
And now you can query your data like this –
// DataContext takes a connection string
DataContext db = new    DataContext("c:\\TestDB\\TestDB.mdf");
// Get a typed table to run queries
Table<Customer>Customers = db.GetTable<Customer>();
// Query for customers by Name
var q = from c in Customers
        where c.Name== "Mark Walker"
       select c;
Well , this is what we did in last blog.I think now you are clear on this.See the image too.



No comments: