Tags: | Categories: Blog Posted by admin on 3/9/2009 5:57 PM | Comments (5)

LINQ to SQL came out with 3.5 and I am still amazed that many people accomplished to stay away from that simple technology. When you ask them, they've heard about but they are not sure how everything works together. Instead of looking it up to learn to see if there is something that may improve their development, they just ignore it.

If you work in software, its your job to keep yourself on the loop for new technologies and languages coming out. Don't need to download everything from Codeplex and play with it, but you should include in your technical book reading a blog/news reading. Of course I keep broadcasting to everybody that hasn't turn me off by now, to subscribe to Community Blogs in ASP.NET and of course ScottGu's blog.

I've included in my interviews to ask a simple question, if you are applying for a ASP.NET job. Do you know who is Scott Guthrie? You'll be amazed how many "ASP.NET developers" don't even know the name. Shocking!

Wanted to show you how to select something from a database and insert a row. For the exercise will use a simple table with a latitude, longitude and ID. If you have used previously dataAdapters aka DataSets in ASP.NET 2.0 you'll find LINQ to SQL familiar. Create a new Item and select LINQ to SQL, drag and drop all the tables you want.

Note: If you modify the table, the LINQ to SQL won't refresh, you'll have to delete and drag and drop again.

image

Select statement you'll find that LINQ provides you with from, where and select out of the box, so you can interrogate the table.

image

Select statement returning strong type. You'll find the => new in 3.5 for LINQ.

image

Insert a new row, make sure you got a primary key in each table you are trying to update. The syntax is familiar if you have been using DataSets/DataTable/DataRow

image

This is as simple as it goes to Select and Insert into a table using LINQ. I would recommend to run this very simple exercise for yourself. Grab an existing database, create a ASP.NET app and generate the LINQ to SQL for the database. Then try to select and insert using this simple example.

We learned by doing things and practicing. After that you'll need to figure it how to update in LINQ to SQL. I bet that after you do that, you'll start writing all your projects with a Database layer using LINQ to SQL.

Cheers

Al

Posted from http://weblogs.asp.net/albertpascual

Comments

on 4/24/2008 8:03 AM

I know Scott Guthrie not Scoot Guthrie Smile


on 4/25/2008 1:39 PM

I think you underestimate the amount of learning required to keep current with Microsoft technologies. It's not a matter of wanting to learn techniques that make your life easier, it's about having the TIME. Some people don't fly out to every developer convention, read every tech blog, or prototype applications for a living... someone has to do the actual work.


on 4/25/2008 1:59 PM

Patrick,


Its great to have you here to do our slacking work Wink


on 9/16/2008 7:31 AM

A truly daunting task you have undertaken to learn all new technologies.


I hope it is going well for ya.


on 11/3/2008 12:18 AM

Finally this weekend I updated the Editor on the GeoTwitter as promised on the previous post . The GeoTwitter


Comments are closed