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

Monday, November 30, 2009

Knowledge Sharing with Peradeniya Engineering Undergraduates

As for my understanding it’s the most beautiful University in Sri Lanka, the Peradeniya University. Thanks to Microsoft Technology Evangelist Wellington and Dinesh Priyankara (MVP – SQL) I got a chance to host two technical sessions for Engineering students at Peradeniya University.

First session was an Introduction to .NET Framework and Visual Studio IDE hosted by me. Windows Server 2008 and IIS was done by Susantha Silva. Third session which was an Introduction to MS SQL Server was done by Dinesh Priyankara (MVP). Back again the fourth session was a Deep Dive session which was on LINQ (Language Integrated Query) done by me. Wellington hosted a session on Silverlight. Also not to forget, Tharindu Nanayakara explained the importance of communities-Student Champ.

Well, it was a good experience as 99% of the students were from an open source background. But I’m sure they were so impressed seeing the new UI and features of Visual Studio 2010. One thing that worries me is, I didn't have enough time to go through all the wonderful features of VS 2010.

Presentations are available to download…

Some pics of the event after the break.

SNC00106IMG_0249[1] SNC00113SNC00127 SNC00135SNC00114SNC00122

Many thanks to Chanarangana Rathnayake and all who supported to make the session a success.

Thursday, December 20, 2007

LINQ - Language Integrated Query (Part 1)

End of another rainy morning. Thought of sharing an end result of a recent R&D, LINQ.

LINQ the Language Integrated Query.
OK… So what’s this so hyped word carry with it. Actually it’s another way of querying data sources within .Net languages.

LINQ libraries came with .NET Framework 3.5, and Visual Studio 2008 IDE can be used to take the maximum out of it. Languages that facilitate LINQ provide type safety as well as compile time checking of queries. VS 2008 provides debugging of LINQ queries, intellisense and refactoring too.

Microsoft has provided us different APIs that provide a gateway to underlying data sources, such as
LINQ to SQL
LINQ to XML
LINQ to DataSets
LINQ to Objects
LINQ to Entities (Still in beta)

Today I’m planning to show a very simple LINQ to SQL query step by step. It’s more like how to write a simple SELECT statement inline C#. OK…Fasten your seat belts.

Step 1
Open Visual Studio 2008 and select a ASP.Net Web Application. Make sure you select .Net Framework 3.5

Step 2
Add a GridView to the to a web form (and add a style to the Grid using Auto Format)

Step 3
Add a Linq to SQL Class.

Step 4
Create a connection to a Database (optional: using Server Explorer). It'll be easy if you add the connection string to the Web.config file.

Step 5
Drag the tables you want, from Server Explorer to the design surface of the Linq to SQL class. Here in this scenario I'll add the Store and the SalesPerson tables. Wow... check out the association created automatically.

Have a look at the properties window. You see the connection which has been accessed from the Web.Config.

OK... Now we have come to the coding part. First create a DataContext of the LINQ to SQL class you have already created. In this case it's AdventureWorksDataContext. Then create a var type variable and assign it to the link query. Yes... the query is not very user friendly until you get used to it. Whats this "s"? It's the structure of the db.Stores. And you can use any letter/word to represent "s". Finally, set the result to the DataSource of the GridView and call the DataBind() method of the GridView.

Build and Run the application.
Cheers!!!