Lost in .NET Code

Developing software in .NET, Security and other ramblings.

Linq Changes from Beta 2 to RTM

Thursday, October 18, 2007

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2060651&SiteID=1

Some of the changes that are coming from Beta 2 to RTM have been published.

Some good news such as .

"Correct handling of database-generated GUID key values" Horray.

Some interesting news..

Previous Method
(Beta1 and Beta2)
Renamed Method
(VS 2008 RTM)

Add()
InsertOnSubmit()

AddAll()
InsertAllOnSubmit()

Remove()
DeleteOnSubmit()

RemoveAll()
DeleteAllOnSubmit()


I know exactly why they are changing this when you first start linq you believe that an Add() would actually add to the database in Linq SQL .. That in fact is not true till you actually submit a change. I.e

using (YYYDatabaseDataContext rdb = new YYYDatabaseDataContext())
{
RssFeed rssFeed = new RssFeed();

rssFeed.CopyRightNotice = "bbc.co.uk/news";
rssFeed.DateAdded = DateTime.Now;
rssFeed.RssUrl = urlFeed;
rssFeed.RssXML = xmlString;
rssFeed.Title = "BBC News";


rdb.RssFeeds.Add(rssFeed);
rdb.SubmitChanges();


}


When you don't add SubmitChanges() your code does not throw any exception or warning it just does not add/change anything to DB. Most devs when first starting with Linq will assume the rdb.RssFeeds.Add(rssFeed) would be good enough, because it is in everything else in .NET such as collections.

This cause serious dev risk in terms of code problems and it is something that I starting to think maybe worth writing a tool to look for this potential issue in large codes basis. I have already come across the issue myself, I have forgotten to add SubmitChanges(). You code looks fine but you seem to lose a record into table through your process.

Although in my heart I welcome the change because it will solve alot of the confusion it is going to be one of those changes that early adaptors will be very frustrated with.

Search and replace for Add is not actually that simple beacuse you use .Add in all sorts of contexts . I.e Generics Lists, collections. So it looks like one of my projects I will be adding a couple of days to project time to move from Beta 2 to RTM. Fair enough the risk of being in early, but it just important lesson to all Devs when building frameworks that naming things correctly from start, gives you alot less pain latter both in support of product but also in making a change late in the day if you have customers out in beta/alpha developing on the platform

Labels: ,


Subscribe in a reader


Blogs I read

Tristan Phillips
Sarah Blow (.Net Mobile)
Mike Taulty (MS DPE)
Ian Griffths (WPF)
Jack Greenfield


Useful Links

Fircroft Trust Ltd
Unwind Software Ltd


Archives

December 2006   January 2007   February 2007   March 2007   April 2007   May 2007   June 2007   October 2007   November 2007   February 2008   April 2008   May 2008   June 2008   July 2008   August 2008   October 2008   November 2008   December 2008   January 2009  


Fun and Games



 

This page is powered by Blogger. Isn't yours?