Archive for the ‘LINQ’ Category

Linq to NHibernate, Version 1.0

Thursday, September 10th, 2009

A few weeks ago, Oren Eini (Ayende Raihan or, as is often referred to) communicated the release of version 1.0 of the Linq provider for NHibernate, a feature highly demanded by users since the advent of integrated query language. NET.

Although it will be included as part of NHibernate product in future versions, have decided to release the current release of the supplier as separate package so you can start to be used from now. It is being tested in many applications in production for several years, and apparently the performance is just right.

And how can help the supplier, if you’re user of NHibernate? The following example from Caffeinated Coder demonstrates how to query database can be simplified and made more readable using Linq and also benefit from strong typing, intellisense and compile-time checks:

Using NHibernate API:

public IList<Call> GetCallsByDate(DateTime beginDate, int interpreterId)
{
    ICriteria criteria = Session.CreateCriteria(typeof(Call))
        .CreateAlias("Customer", "Customer")
        .Add(Restrictions.Gt("StartTime", beginDate))
        .Add(
            Restrictions.Or(
                Restrictions.Lt("EndTime", DateTime.Now), Restrictions.IsNull("EndTime"))
            )
        .Add(Restrictions.Eq("Interpreter.Id", interpreterId))
        .AddOrder(Order.Desc("StartTime"))
        .AddOrder(Order.Desc("Customer.Name"));
        return criteria.List<Call>() as List<Call>;
}

Using Linq:

public IList<Call> GetCallsByDateWithLinq(DateTime beginDate, int interpreterId)
{
    var query = from call in Session.Linq<Call>()
        where call.StartTime > beginDate
            && (call.EndTime == null || call.EndTime < DateTime.Now )
            && call.Interpreter.Id == interpreterId
        orderby call.StartTime descending, call.Customer.Name
        select call;

    return query.ToList();
}

You can download both binaries and source code from the SourceForge project page.

LINQ to SQL changes in VS 2010 & .NET 4.0

Wednesday, June 17th, 2009

For some time did not read anything about LINQ To SQL, and the truth is that I had raised was going with this extension of LINQ in Visual Studio 2010 and. NET 4.0 … well, the fact is that work has continued in LINQ To SQL and brings a lot of developments. NET 4.0. You can access all the news in this link.

via Damieng

LinqPad

Thursday, April 23rd, 2009

I just learned of the existence of a very interesting tool called LinqPad, which allows query data using LINQ with. Net Framework 3.5.

Click on the image to view large.

Allows queries like:

a) LINQ to SQL
b) LINQ to Objects
c) LINQ to XML

After doing some tests I can say that is an excellent tool, very comprehensive and allows flexibility to experience the power of LINQ and more of this interesting framework, which aims to be the big bet. NET for data access.

Read More about LinqPad

How To Create An XML Document In C#

Sunday, March 29th, 2009

It is very easy, as there I wondered, here is the code:

?View Code CSHARP
using System.Xml.Linq
protected void CreateDocumentXML ()
{
XDocument TheCodersXML = new XDocument(
new XDeclaration("1.0","utf-8","yes")
new XComment("List of Students")
new XElement("Students"
new XElement("Student"
new XAttribute("Id","No:123")
new XElement("Name","Diana Wallwalker")
new XElement("Age","23")),
 
new XElement("Student"
new XAttribute("Id","No:456")
new XElement("Name","Danny Thomas")
new XElement("Age","27")),
 
new XElement("Student"
new XAttribute("Id","No:789")
new XElement("Name","Roger Benny")
new XElement("Age","20")),
 
new XElement("Student"
new XAttribute("Id","No:012")
new XElement("Name","Venu Thomas"),
new XElement("Age","26"))
)
);
}

In the end it saved in the address you want:

?View Code CSHARP
TheCodersXML.Save(@"c:\TheCodersXML.xml");

 

 Output:

<?xml version="1.0″ encoding="utf-8″ standalone="yes"?>
<!-- List of Students -->
<students>
	<student Id="No:123">
		<name>Diana Wallwalker</name>
		<age>23</age>
	</student>
	<student Id="No:456">
		<name>Danny Thomas</name>
		<age>27</age>
	</student>
	<student Id="No:789">
		<name>Roger Benny</name>
		<age>20</age>
	</student>
	<student Id="No:012">
		<name>Venu Thomas</name>
		<age>26</age>
	</student>
</students>

Over 22 Links To LINQ

Tuesday, March 24th, 2009

LINQ Index

Charlie Calvert’s Blog- Links to LINQ: Click Here..
The Server Side – LINQ/C# Learning Guide: Click Here..

LINQ Bloggers

Troy Magennis – LINQed IN: Click Here..
Charlie Calvert’s Community Blog: Click Here..
LINQ- The Wandering Glitch: Click Here…
OakLeaf Systems: Click Here..

LINQ Websites

LINQDev:
LINQ in Action:

LINQ Videos

LINQ Video:
Luke Hoban: Orcas – Compiling LINQ, C# Futures, Intellisense

LINQ Books

Amazon.com: Pro LINQ: Language Integrated Query in C# 2008 (Windows.Net) (Paperback)
Amazon.com: LINQ for Visual C# 2005 (Paperback)
Amazon.com: LINQ for VB 2005 (Paperback)

LINQ Articles

SingingEels: Improving Performance With LINQ
Next-Generation Data Access: Making the Conceptual Level Real
LINQ ASP.NET Sitemap
LINQ Lazy Evaluation
Query Windows Forms Controls in LINQ
Enumerable.Range in C#
ToDictionary Method in C#

From Microsoft

LINQ Project General
LINQ 101 Samples

Some other books for ASP.NET MVC, LINQ, Silverlight, ASP.NET 3.5, Sharepoint Server. Click Here..

Intro to LINQ (Language Integrated Query)

Wednesday, March 11th, 2009

Introduction to LINQ (Language Integrated Query)

LINQ (Language Integrated Query) and .Net Framework 3.5 in a variety allows you to query the data in a standardized way for the typed of data collection, it features an integrated language. Development Tools Visual Studio 2008 are supported.

LINQ is a language that supports the standard query operators are defined, you can filter the enumeration process and the projection of a common syntax for different data sets.

Example:

Select from the set of formulas to the LINQ query expression. In this code, strName are extracted from the beginning with ‘v‘, it is stored in str, it is output in sequence foreach

?View Code CSHARP
string [ ]  strName =
{
"Benny",
"Venu",
"Roger",
"Thomas",
"Varghese",
"Danny"
} ;
var str = from x in  strName
where x[0]  == 'v'
select x;
 
foreach ( var y in  str )
{
Console. WriteLine (y) ;
}

Language Specification:

LINQ is a language, LINQ is introduced together with the new language version in order to provide more capacity. For example, the query expressions, extension methods, lambda expressions, anonymous types and so on. As for the example in C# we would like to be referred to the specification from of C# 3.0.

Data Source:

LINQ, including those by third parties, may be applied to any type of data source. This is achieved by adding to the data source as a method for extending the standard query operators.

The traditional set of objects for sorting and enumerated data types and a similar array to handle efficiently the filter (Array class) by using the object or collection. The databases and XML data set on the ADO.NET operation was necessary and is treated as different data sets. LINQ by, and can be treated without distinction in the common data sets and objects. Compared with other languages, Ruby and Active Record is a combination of excellent handling of this collection are believed to be extended to counter-conscious language.

For example, Microsoft will be implemented by the following.

  • LINQ to ADO.NET
    • LINQ to SQL (DLinq)
    • LINQ to Entities
    • LINQ to DataSet
  • LINQ to XML (XLinq)
  • LINQ to Objects

The Language Which Corresponds to LINQ

  • C# 3.0
  • F# 1.1.8.1
  • Visual Basic 9.0

As for C++/CLI as for the schedule which corresponds to LINQ it is not, the library related to LINQ it can be used only is until recently with sentence structure of sort.