Monthly Archives: May 2010
Types of LINQ
LINQ to Objects: Provides queries on any kind of C# in-memory object, such as arrays, lists, and other collection types. LINQ to XML: Provides creation and manipulation of XML documents using the same syntax and general query mechanism as the … Continue reading
Join Query in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQJoinQuery { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Set operators in LINQ
LINQ provides standard set operators such as Union() and Intersect() that operate on query results. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQSetOperators { class Customer { public string ID { get; set; } public string City … Continue reading
Using First and FirstOrDefault in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQFirstOrDefault { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Example of Take and Skip in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQTakeAndSkip { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Using a Group Query in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace GroupQuery { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Ordering By Multiple Levels in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace MultiLevelOrdering { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Using Any and All in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQAnyAndAll { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Select Distinct Query in LINQ Projection
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQSelectDistinct { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Creating New Objects in Queries using LINQ Projection
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ProjectionCreateNewObjects { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Querying Complex Objects in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace QueryComplexObjects { class Customer { public string ID { get; set; } public string City { get; set; } public string Country { get; set; } public string Region { … Continue reading
Example of Numeric Aggregates in LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace NumericAggregates { class Program { static void Main(string[] args) { int[] numbers = CreateNumbers(12345678); Console.WriteLine("Numeric Aggregates example in linq"); var queryResults = from n in numbers where … Continue reading
Aggregate operators in LINQ
Count() Count of results Min() Minimum value in results Max() Maximum value in results Average() Average value of numeric results Sum() Total of all of numeric results
Querying a Large Data Set using LINQ
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LargeNumberQuery { class Program { static void Main(string[] args) { int[] numbers = CreateNumbers(7384738); Console.WriteLine("Numbers less than 2000:"); var queryResults = from n in numbers where n < … Continue reading
LINQ OrderBy in Query Syntax
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace OrderQueryResults { class Program { static void Main(string[] args) { string[] names = {"kaka", "kunka", "kumar", "James", "Smith"}; var queryResults = from n in names where n.StartsWith("k") orderby n … Continue reading
Use LINQ to find names starting with specific alphabet and method syntax
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace LINQMethodSyntax { class Program { static void Main(string[] args) { string[] names = { "kaka", "kunka", "kumar", "James", "Smith"}; var queryResults = names.Where(n => n.StartsWith("k")); Console.WriteLine("Names beginning with … Continue reading
Use LINQ to find names starting with specific alphabet and query syntax
Example to use LINQ to find names starting with a specific alphabet (k). using System; using System.Collections.Generic; using System.Linq; using System.Text; static void Main(string[] args) { string[] names = { "kaka", "kunka", "kumar", "James", "Smith"}; var queryResults = from … Continue reading
Join two MySQL tables together
SELECT a.column1, b.column1, b.column2 FROM tablename a JOIN tablename b ON a.column1 = b.column1 WHERE a.column1 LIKE ‘%something%’
Using MySQL SELECT to count rows in a table
MySQL count() Returns a count of the total number of rows in a table. SELECT COUNT(*) from TableName
Using MySQL SELECT to return first 10 rows
To return the first 10 rows we should run a SQL Select statement and limit the number of rows returned. This is useful when we only want to return a few rows to do some initial analysis. SELECT column1, column2, … Continue reading