0

I'm using SharePoint 2010 Foundation with LINQ for SharePoint list. I've generate my DataContext using spmetal command.

Now I'm trying to access data but I have this error:

ArgoumentException error: Value does not fall within the expected range.

This is the code that crash:

        using (DataContext context = new DataContext(SPContext.Current.Web.Url))
        {
            List<MyListFieldsContentType> tasks = context.Task.Where(x => x.Code.Id == id).ToList();

I think that the problem is with .ToList() command because without .toList() I haven't error.

More details about error:

Value does not fall within the expected range. at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName, Boolean bThrow) at Microsoft.SharePoint.SPListItemCollection.GetColumnNumber(String groupName, Boolean bThrowException) at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, Int32 iIndex, Boolean bThrow) at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw, Boolean bThrowException) at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) at Microsoft.SharePoint.SPListItem.get_Item(String fieldName) at Microsoft.SharePoint.Linq.PropertyMap.GetSPFieldValue(PropertyMap pm, SPListItem item, JoinPath joinPath) at Microsoft.SharePoint.Linq.PropertyMap.GetFromListItem(DataContext dc, SPListItem item, Object entity, JoinPath joinPath) at Microsoft.SharePoint.Linq.SPItemMappingInfo.MaterializeEntity[TEntity](DataContext dc, SPDataList list, SPListItem item, SPItemMappingInfo itemMappingInfo, JoinPath joinPath) at lambda_method(ExecutionScope , SPListItem ) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at Acm.DataAccessLayer.Acquisition.LinqDalAcquisitionTask.GetByAcquisitionId(Int32 id) at AcquisitionTool.Layouts.AcquisitionTool.AllAcquisitionsGantt.GetChartData()

Please, can you help me?

4
  • You can use the data.Configuration.LazyLoadingEnabled = false; before getting the data using .ToList()
    – Hardik
    Commented May 6, 2016 at 11:23
  • Hi, I tried but without success. I've added this code: context.DeferredLoadingEnabled = false;
    – ilMattion
    Commented May 6, 2016 at 12:29
  • Debugging my application I noticed that using quickwatch I need wait some second for view result.
    – ilMattion
    Commented May 6, 2016 at 12:30
  • Check my updated answer
    – Hardik
    Commented May 6, 2016 at 12:36

1 Answer 1

0

UPDATED

It might possible that lookup fields were omitted from the query results because the list exceeds the lookup column threshold.

To solve it, go to Central Administrator -> Application management -> Manage Web Applications select one, then on top General Settings -> Resource Throttling there change default (8) List View Lookup Threshold value to a bigger one, in my case 12 was the lowest accepted value.

That's it! It might solve your issue...!

You can get SharePoint List items using below mentioned code.

// Get DataContext from page context
using (DataContext context = new DataContext(SPContext.Current.Web.Url))
{

        // Get the SharePoint list
        EntityList<Task> Customers = data.GetList<Task>("Task");

        var Tasks = from customer in Customers
                              where customer.Id == id
                              select customer;

        foreach (var Task in Tasks)
        {
            Console.Writeline("id = {0}, Task.CustomerId);
        }
}
9
  • Hi, I've tried but I obtain the same error in: var Task.
    – ilMattion
    Commented May 6, 2016 at 11:40
  • Than your entity is not bound properly
    – Hardik
    Commented May 6, 2016 at 11:41
  • Thanks for your support. What can I do? I have not changed DataContext class.
    – ilMattion
    Commented May 6, 2016 at 11:42
  • can you please post the entire error? so i can help you better
    – Hardik
    Commented May 6, 2016 at 11:47
  • Hi, I've edited the post with the stacktrace. There is not InnerException.
    – ilMattion
    Commented May 6, 2016 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.