Posts Tagged ‘LINQ to SQL’

Easy Data-loading with LINQ-to-SQL and LINQ-to-XML

.Net 3.5 had some nice tricks in it. LINQ-to-XML was one of them. With the new "X"-types, you can make working with XML really easy. VB.Net 9 takes it one step further, and lets you write XML in your code without strings. "Hey Rich, that’s old news," I hear you say. "And who’s interested in [...]

More »

LINQ or DIE

I just read a fantastic quote about LINQ from the book Pro LINQ: Language Integrated Query in C# 2008 by Joseph C. Rattz, Jr.: I prefer to think of LINQ as a data iteration engine, but perhaps Microsoft didn’t want a technology named DIE. I think they already built the technology for such a product, [...]

More »

A Pure ASP.Net Grid with Grouping

One of my favorite bloggers is Matt Berseth. Nearly once a week he comes up with a post where he does something amazing with the standard ASP.Net controls. I usually read his posts in awe. He’s really good. But he’s not only is a good developer, he’s a great writer. Even though his posts are [...]

More »

The LinqDataSource and the Hidden Viewstate

Yesterday I thought I’d learn about the LinqDataSource in ASP.Net 3.5, and got an interesting surprise. The new LinqDataSource can also be used with a LINQ-to-SQL model to perform updates. You simply add the DataSource to your page, set the table name, and set EnableUpdate to true. Then, using a standard DataControl, you can make [...]

More »

How to Update Data with LINQ-to-SQL

When learning LINQ-to-SQL, it’s not immediately obvious how to do an update. Querying is easy, and there are methods for inserting and deleting. Updating usually occurs by modifying an object already known to the DataContext and then calling SubmitChanges on the context. var product = (from p in dataContext.Products where p.ProductID == 1 select p).Single(); [...]

More »

How to See the SQL Generated by a LINQ to SQL Command

Quick tip: If you want to see the SQL generated by LINQ to SQL for a query or command, simply set the Log property of your generated DataContext class to an instance of a TextReader. If this is your code: using System; using System.Linq; using System.Data.Linq; namespace LINQtoSQLConsole { class Program { static void Main(string[] [...]

More »