language integrated query by nyros developer
DESCRIPTION
Language Integrated Query By Nyros DeveloperTRANSCRIPT
WELCOME TO ALL
LINQ
Language Integrated Query provides built - in language querying functionality similar to SQL.
LINQ defines a set of standard query operators in the System.Linq namespace to select, filter, aggregate, and partition data.
LINQ is a new feature in Visual Studio 2008 and the .NET Framework 3.5
Components in LINQ
• System.Linq Contains the set of standard query operators and types and interfaces.
• System.Data.Linq Contains classes that support interaction with relation data base.
• System.Xml.Linq Contains classes for LINQ to XML
Operators in LINQ
• Average
• Cast
• ElementAt
• ElementAtOrDefault
• First
• FirstOrDefault
• Last
• Reverse
• Skip
• SkipWhile
Example on Operators
int[] nums = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024 };
int num1 = nums.First<int>();
int num2 = nums.First<int>(x => x > 50);
int num3 = nums.FirstOrDefault<int>(x => x > 5000);
Console.WriteLine(
num1.ToString() + "-" +
num2.ToString() + "-" +
num3.ToString());
LINQ Provider
It is a gate for LINQ to act up on data that is not inside a queryable type.
1)Linq to Objects
2)Linq to XML
3)Linq to SQL
4)Linq to Datasets
LINQ to Objects
string[] country = { "India","China","America", "Nepal" };
IEnumerable<string> query = from n in country where n.Length == 5 orderby n descending select n;
foreach (string name in query)
{
Response.Write(name.ToString());
}
LINQ to XML
XElement countries = XElement.Parse( @"<countries> <country>India</country> <country>China</country> <country>America</country> </countries>" );
IEnumerable<string> query = from n in countries.Elements("country") where n.Value.Length == 5 orderby n.Value descending select n.Value;
LINQ to SQL
It allows .NET developers to write "queries" in their .NET language of choice.
The LINQ to SQL provider allows LINQ to be used to query SQL Server databases as well as Sql server compact database.
It has better support for server oriented features. It is less complicated. It has some what better performance.
SELECT ContactId, FirstName,LastName,DateOfBirth,Phone,Email
FROM [Contact]
WHERE DATEADD(YEAR, @p0, DateOfBirth) > @p1
ORDER BY DateOfBirth DESC
DataContext db = new DataContext("");
var q = from c in db.Contact
where c.DateOfBirth.AddYears(35) > DateTime.Now
orderby c.DateOfBirth descending
select c;
LINQ on DataSets
The DataSet is an in-memory representation of relational data
SqlDataAdapter da = new SqlDataAdapter(
"SELECT * FROM Customers",
_connectionString);
DataTable customers = new DataTable("customers");
da.Fill(customers);
int countOfCustomers =
(from c in customers.AsEnumerable()
where c.Field<string>("Country") == "France"
select c).Count();
Conclusion
• We can work on diverse data bases like Objects,SQL,DataSets....
• Provides consistency by defining a set of standard query operators
• Deeply integrated into .Net languages
• Intellisense for auto-completion Performance is high
• Compiler can perform syntax and type checking on query expressions
• It is very powerful all on its own.
THANK YOU