< Browse > Home /

| RSS

Create T-SQL CASE Statements With LINQ To SQL

I was recently helping Nosh with a LINQ To SQL query where he wanted the resulting T-SQL query to have CASE statements. Having CASE statements in T-SQL queries is a common scenario but how do we it in LINQ To SQL .After some investigation I found the solution which I am presenting here using an [...]

[ More ] March 24th, 2009 | No Comments | Posted in Programming |

Get Last Row From Table Using LINQ To SQL

This query returns the last row from Sales.Customer table in Adventure Works database. I am using LINQPad to write and execute my query.
(from c in Customers
select c)
.OrderByDescending(x=> x.CustomerID).First()
 
Here is the result as displayed in LINQPad
 

[ More ] March 9th, 2009 | No Comments | Posted in Code Snippets |

LINQ Equivalent Of Where IN With Int

Earlier I wrote a post showing how to write a LINQ query which gets transformed into a T-SQL query with a "Where In" clause. I had a comment on the post by Steve saying that the approach only works with strings. In this post I will show you a similar query which works with Integers.
Let’s [...]

[ More ] January 5th, 2009 | No Comments | Posted in Programming |

LINQPad with Intellisense

I had a look at LINQPad few months ago when I wrote about how you can use this tool to view generated LINQ To SQL Queries. There is not doubt that LINQPad comes in as a very handy tool when writing LINQ queries. But writing queries in LINQPad has not been that easy. Until Now!
LINQPad [...]

[ More ] December 23rd, 2008 | No Comments | Posted in Programming |

Remove Duplicate Lines From A Text File Using LINQ

A question was posted on c-sharpcorner forums asking how you would remove duplicate lines from a text file. It got me thinking about how this problem could be addressed using LINQ. Before I get into the solution, here is the problem statement.
The problem
I am trying to remove duplicate lines from a text file. To [...]

[ More ] December 12th, 2008 | 1 Comment | Posted in Programming |

Dynamic Sort With LINQ To SQL

Sometime ago I wrote a post showing how to do dynamic sort with LINQ. That approach worked well with LINQ To Objects. Today I spotted a question on the forums where Levi asked a question about doing dynamic sorts with LINQ To SQL. My earlier approach will work once all the data is retrieved on [...]

[ More ] November 19th, 2008 | 9 Comments | Posted in Programming |

Enum Support With LINQ To SQL And SqlMetal

As a programmer I love my enums. I find code written using enums to be more readable than without them. However, there has been and there still is a disconnect between lookup tables in a database and enums in code. One has to restore to some creative trickery to get them working in harmony. Recently [...]

[ More ] November 18th, 2008 | 2 Comments | Posted in Programming |

Free LINQ To SQL Training In Sydney

I am running a LINQ To SQL Training day on Saturday November 8th at Microsoft Office in North Ryde. The course is FREE for anyone to attend but there are only 20 places available. So if have not yet jumped into the wonderful world of writing LINQ queries. If you are considering LINQ To SQL [...]

[ More ] October 29th, 2008 | No Comments | Posted in News |

View T-SQL Query Generated By LINQ To SQL Using Linqpad

In my previous post I showed you three different ways to capture the T-SQL query generated by LINQ To SQL. A comment on the post reminded me that I forgot to mention a fourth way i.e. using Linqpad. In Linqpad when you have executed the query you can click on the SQL tab next to [...]

[ More ] September 23rd, 2008 | 1 Comment | Posted in Programming |

View T-SQL Query Generated By LINQ To SQL

While working with LINQ To SQL there are times when you are interested in looking at the query which will be executed on the database.  This post will cover different ways you can capture the query generated by LINQ To SQL.
SQL Server Profiler
SQL Profile has long been a preferred tool to capture activity on a [...]

[ More ] September 22nd, 2008 | 3 Comments | Posted in Programming |

Use SqlConnection With LINQ To SQL

LINQ To SQL allows us to use a SqlConnection object to connect to a database. The way to use a SqlConnection is to pass it as a parameter to DataContext object. DataContext object has constructor which takes in a IDbConnection and SqlConnection implements this Interface. Here I create a SqlConnection object and use it to [...]

[ More ] September 16th, 2008 | 4 Comments | Posted in Programming |

LINQ To SQL Join On Multiple Conditions

LINQ To SQL or just plain LINQ allows us to do a join on multiple conditions using an elegant technique. In this post I will show you how to perform a Join on multiple conditions. As an example I will take two tables called House and ShoppingMall.

Both these tables have PostCode and CouncilCode as common [...]

[ More ] September 16th, 2008 | 6 Comments | Posted in Programming |
  • Page 1 of 2
  • 1
  • 2
  • >