Contents tagged with IntelliSense

  • 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.

    Read more...