language integrated query by nyros developer

13

Click here to load reader

Upload: nyros-technologies

Post on 10-May-2015

1.294 views

Category:

Documents


3 download

DESCRIPTION

Language Integrated Query By Nyros Developer

TRANSCRIPT

Page 1: Language Integrated Query By Nyros Developer

WELCOME TO ALL

Page 2: Language Integrated Query By Nyros Developer

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

Page 3: Language Integrated Query By Nyros Developer

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

Page 4: Language Integrated Query By Nyros Developer

Operators in LINQ

• Average

• Cast

• ElementAt

• ElementAtOrDefault

• First

• FirstOrDefault

• Last

• Reverse

• Skip

• SkipWhile

Page 5: Language Integrated Query By Nyros Developer

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());

Page 6: Language Integrated Query By Nyros Developer

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

Page 7: Language Integrated Query By Nyros Developer

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());

}           

Page 8: Language Integrated Query By Nyros Developer

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;

Page 9: Language Integrated Query By Nyros Developer

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.

Page 10: Language Integrated Query By Nyros Developer

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;

Page 11: Language Integrated Query By Nyros Developer

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();

Page 12: Language Integrated Query By Nyros Developer

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.

Page 13: Language Integrated Query By Nyros Developer

THANK YOU