1
    var updateItem = (from item in ctx.LI_MyList
              where
              item.Id == 1
              select item).First();

I got the following exception when executing the query:

System.ArgumentException: Value does not fall within the expected range.

However InsertOnSubmit () is working, I tried the query with LINQPad but I got the same exception, here is LINQPad StackTrace:

The same list is responding normaly to CAML queries,

The same query is running normaly on other lists in the same site,

I Googled the exception but it seems to be caused by various reason.

Excuse my English and feel free to edit the question.

Gynteniuxas
  • 7,035
  • 18
  • 38
  • 54
Mosbah
  • 1,347
  • 1
  • 14
  • 28

1 Answers1

-1

Is there an item with ID equal to 1?

If not your query will not return results and the .First() function will fail.

If possible try the FirstOrDefault() function but you will need an extra test to check if your 'updateitem' variable is not null.

Wout
  • 964
  • 1
  • 6
  • 19
  • yes I already ionserted items, LI_MyList.Count() is returning 4, from item in LI_MyList where item .Id == 1 select item this query in LINQPad is returning the same exception. Thanks for the quick replay. – Mosbah Feb 10 '12 at 09:17
  • I figured it out, one of the fields was causing the problem. – Mosbah Feb 10 '12 at 10:08
  • I've run into this problem as well. I think this is a bug with the WorkflowStatus column. Be sure to exclude column that in the SPMetal parameter file. Here's a useful link... – Jason Turan Feb 22 '12 at 03:26
  • http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/1c00419a-f616-4556-8098-545f82ff1a3f/ – Jason Turan Feb 22 '12 at 03:26