Search


Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Friday, April 4, 2008

Advantages LinQ (ADO.NET)

Assume you have deployed the framework 2.0 code into production along with the database, which has the column names as specified in the select query. Later, the database administrator (DBA) decides to change the column names in all the tables to implement new database policies: he modifies the employees table and changes the firstname column to EmployeeFirstName and the lastname column to EmployeeLastName. After these database changes are made, the only way to prevent the application from breaking is by modifying all the code segments in source code that refers to the firstname and lastname columns, rebuild, retest, and deploy the whole application again. Though on the surface it seems not so difficult to make such changes, if you factor in the possibility that there might be many database-related code segments that require modification of the column names according to the new column naming scheme, this can end up being a tedious and difficult approach to upgrade an application so it can work with the modified database.

Thursday, April 3, 2008

LinQ to SQL

before: string query = “SELECT * FROM Products WHERE categoryId = 3”; SqlCommand command = new SqlCommand(); command.CommandText = query; there might be: - runtime error in query... C# can't detect if we spell fron for FROM Thus, with LINQ: SomeDataContext database = new SomeDataContext(); List products = from p in database.Products where p.Price > 300 && p.CategoryId == 3 select p; OR with new C# 3.0 feature lambda expression '=>' SomeDataContext database = new SomeDataContext(); Category aCategory = database.Categories.Single(c => c.Id == 7); c => c.Id == 7 is lambda expression which means to get some c as category where id of c is 7

Tuesday, April 1, 2008

LINQ: - LinQto Object : use of standard query operator (SQO) for pulling data from any object that can be implemented by interface IEnumerable. This query can be use for data in memory. - LinQ to ADO.NET: LinQ to SQL , LinQ to dataset, LinQ to Entities - LinQ to XML hello word in LinQ: class Program { static void Main(string[] args) { string[]helloWord={"hello","this","is", "LINQ","by","Philip","H" }; var results = from word in helloWord where(word[0]>'g' || (word[0]>'K'&& word[0]<'M')) select word+' '; foreach(var wordItem in results) Console.Write(wordItem); } }

Thursday, March 27, 2008

C# 3.0 : 5 new features

5 new features for C# 3.0: - lambda expression ( [input parameter] => [expression or statement] ) - Var keyword ( used for unknown type, collection, or object) var object = new {name="john", age=22); [anonymous type] - extension method add more method using static class -->example: public static string threeFirstLetters ( this string x) this will create another method in string class. cool~ - partial method declaration and implementation can be in different file - query expression ex : helloword.Where(word => (word[0] >'g').Select(word => word+' ');