Jonas Stawski

Everything .NET and More

Linq To Sql not updating on Context.SubmitChanges()

Tonight I ran into a weird problem that I haven’t seen before. I was getting an entity back from a query, changing some values, and calling the DataContext.SubmitChanges() and the database was not being updated. The code ran fine without any ex... [More]

Recreating Entities with Linq To SQL

Be very careful when you need to recreate your entities with Linq to SQL. If I added a new column to the table and I needed to refresh my entity I used to remove it from the design and re add it again. This has worked for a while until now when all o... [More]

LINQ To SQL Generic Detach

UPDATE: you can read Jowen Mei's post for an updated version of this code. Anyone who has been trying to use LINQ To SQL with ASP.NET would know of the problems of dealing with state. Since LINQ To SQL does require to maintain state of the entitie... [More]

LINQ to SQL Debug Visualizer

One of the cool features about Visual Studio is that you can extend it. One of the many things you can extend are the debugging Visualizers. While you're debugging an application with Visual Studio 2005 and 2008 you can hover over a variable and you ... [More]

Multiple Order By in LINQ with extension methods

For some reason I am inclined to write LINQ expressions using the Extension Methods. You know the one that looks something like this: Context.Products.Where(p => p.ProductID > 100).OrderBy(p => p.Description).ToList(); Well the other day I... [More]

Dynamic Construction of a LINQ Expression

One of the great things about LINQ is it's deferred execution. Read about deferred execution here and here. What does this mean to us developers? Well it means many things, but one of those things is that you can dynamically construct your LINQ expre... [More]

Dynamic Ordering with LINQ

I was in need to order by a sort expression passed in to a function and since I am using LINQ to SQL the only supported way to do this is by having a switch clause and construct the orderby clause based on the sort input. This could result in a huge ... [More]