IntelliSense Fosters Inattention

I count on IntelliSense a lot when programming - especially in C# which (arrggh!) is case-sensitive. However, I just had a case where IntelliSense led me to make a mistake that cost me half an hour.

I was happily working in LINQ and had the following code:

protected void LinqDataSource1_Deleting
    (object sender, LinqDataSourceDeleteEventArgs e)
{
    NWDataClassesDataContext dc = new NWDataClassesDataContext();
    Product prod;
    prod = (Product)e.OriginalObject;
    var q = from o in dc.Order_Details
            where o.ProductID == prod.ProductID
            select o;
    foreach (Order_Detail od in q)
    {
        dc.Order_Details.DeleteAllOnSubmit(od); // fails!
    }
    dc.SubmitChanges();
}

There was an error in the foreach loop:

The type arguments for method 'System.Data.Linq.Table<Order_Detail>.DeleteAllOnSubmit<TSubEntity>(System.Collections.Generic.IEnumerable<TSubEntity>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.  

After going in circles (and unsuccessfully searching the error message), I finally understood what the error was telling me: I had blithely accepted the DeleteAllOnSubmit() method which came first in the alphabetical list of members. The method that I really wanted was the next item in the IntelliSense listbox, DeleteOnSubmit() as shown here:

protected void LinqDataSource1_Deleting
    (object sender, LinqDataSourceDeleteEventArgs e)
{
    NWDataClassesDataContext dc = new NWDataClassesDataContext();
    Product prod;
    prod = (Product)e.OriginalObject;
    var q = from o in dc.Order_Details
            where o.ProductID == prod.ProductID
            select o;
    foreach (Order_Detail od in q)
    {
        dc.Order_Details.DeleteOnSubmit(od);
    }
    dc.SubmitChanges();
}

I probably wouldn't have goofed up if forced to type the method name rather than hitting Tab to select something from IntelliSense.

Hmmm. Perhaps I shouldn't admit that I lose time on silly mistakes like this?  Oh well. My hope is that someone else will find this blog entry while searching the error message and profit from my inattention.

Published Saturday, July 26, 2008 12:09 PM by Ken Cox [MVP]

Comments

# re: IntelliSense Fosters Inattention

Saturday, July 26, 2008 2:59 PM by Martin Ennemoser

Why not skip the foreach loop altogether and just do a:

dc.Order_Details.DeleteAllOnSubmit(q);

It's less code and IntelliSense would have been(though accidentally) right in the first place.

# re: IntelliSense Fosters Inattention

Saturday, July 26, 2008 6:53 PM by Daniel

How in the world did this take 30 minutes to track down. :P

# re: IntelliSense Fosters Inattention

Saturday, July 26, 2008 7:26 PM by paul.vencill

What you fail to mention is the amount of time intellisense saves you when it's right and/ or when you're paying attention.  Over the course of a project, I guarantee it works out to more than a half hour of reduced code, especially if (like me) you've added in code snippets and the like.

# re: IntelliSense Fosters Inattention

Saturday, July 26, 2008 11:44 PM by Ken Cox [MVP]

@Martin: Good eye! If I hadn't been porting code, that would be perfect.

@Daniel: It's not funny, is it? <grin> Seriously, I kept focusing on the code that precedes the problem line. I learned that debugging a LINQ query is not a pleasant experience... it's one big blob at the breakpoint!

@Paul: I agree 100%. As I say, IntelliSense saves my butt a million times over, especially by providing the proper case and syntax in C#. It's just that - like copy and paste - the tool's effectiveness decreases when the problem occurs between the keyboard and the chair. <grin>

Ken

# re: IntelliSense Fosters Inattention

Friday, July 10, 2009 12:54 PM by Mark Orlando

I'm very happy you blogged this post Ken. I am trying to Learn ASP.NET MVC and LINQ from the new NerdDinner book and got hung up here. Your post allowed me to figure out the problem in my code and move on with my efforts. Thanks again!

# re: IntelliSense Fosters Inattention

Friday, July 15, 2011 6:11 AM by Peter

@Ken: Thanks! That saved me a few minutes to find out what's the problem.

@Daniel: You are right. I just realized sometimes we just turn to google every time we have an error message instead of thinking.

On the other hand that is not exactly the error message that I would expect for an error like this.

Leave a Comment

(required) 
(required) 
(optional)
(required)