This is a migrated thread and some comments may be shown as answers.

Client side binding using ORM with normal WebService but PropertyDescriptor _descriptor is always null

1 Answer 60 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mandy
Top achievements
Rank 2
Mandy asked on 24 May 2011, 10:33 AM
Hello Admin,

  i had used the client side binding using ORM with normal WebService , but i am keep getting the error when i trying to sort the grid , the grid bind successfully and paging also works fine but the sorting gives me error of object reference not set to instance of an object. i tried to debug and found that the PropertyDescriptor _descriptor = null; is always null .i had used reverse mapping of ORM and maps the two different tables. below is my code ..


[WebMethod(EnableSession = true)]
    public List<ProjectUserMapping> GetData(int startRowIndex, int maximumRows, string SortField, GridSortOrder SortOrder)
    {
        List<GridSortExpression> sortExpression = new List<GridSortExpression>();
        if (SortField != "")
        {
            GridSortExpression item = new GridSortExpression();
            item.FieldName = SortField.ToString();
            item.SortOrder = SortOrder;
            sortExpression.Add(item);
        }

        IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope();

        //var query = scope.Extent<ProjectUserMapping>().ToList();
        var result = from o in scope.Extent<ProjectUserMapping>()
                     where o.UserId.Equals(Convert.ToInt32(Session["UserId"]))
                     select o;
        var query = result.ToList();
        List<ProjectUserMapping> list = new List<ProjectUserMapping>();
        list = query;
        ///Getting Paging and sorting
        list = GetProjectsPagingAndSorting(list, startRowIndex, maximumRows, sortExpression); 
        return list;
    }



#region Sorting Paging

    public class GridGenericSorter<T> : IComparer<T>
    {
        GridSortExpression _expression = null;
        PropertyDescriptor _descriptor = null;

        public GridGenericSorter(GridSortExpression expression)
        {
            _descriptor = TypeDescriptor.GetProperties(GetType().GetGenericArguments()[0]).Find(expression.FieldName, true);
            _expression = expression;
        }

        public int Compare(T o1, T o2)
        {
            IComparable comparable1 = (IComparable)_descriptor.GetValue(o1);
            IComparable comparable2 = (IComparable)_descriptor.GetValue(o2);

            if (_expression.SortOrder == GridSortOrder.Ascending)
            {
                return comparable1.CompareTo(comparable2);
            }
            else
            {
                return comparable2.CompareTo(comparable1);
            }
        }
    }

    /// <summary>
    /// Getting Project paging and Sorting
    /// </summary>
    /// <param name="data"></param>
    /// <param name="startRowIndex"></param>
    /// <param name="maximumRows"></param>
    /// <param name="sortExpression"></param>
    /// <returns></returns>
    public static List<ProjectUserMapping> GetProjectsPagingAndSorting(List<ProjectUserMapping> data, int startRowIndex, int maximumRows, List<GridSortExpression> sortExpression)
    {
        if (sortExpression.Count > 0)
        {
            foreach (GridSortExpression expression in sortExpression)
            {
                data.Sort(new GridGenericSorter<ProjectUserMapping>(expression));
            }
        }
        List<ProjectUserMapping> list = new List<ProjectUserMapping>();
        startRowIndex = startRowIndex >= data.Count ? 0 : startRowIndex;
        decimal Count = data.Count - startRowIndex;
        for (int i = 0; i < Math.Min(maximumRows, Count); i++)
        {
            list.Add(data[i + startRowIndex]);
        }
        return list;
    }


    #endregion


 
Please post the reply asap....


Thanks,
Mandeep Singh

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 26 May 2011, 05:04 PM
Hi Mandeep Singh,

Could you please provide us with a sample application that demonstrates the wrong behavior in order to investigate the cause for the error further?
I have changed the thread type to Product Feedback in order to enable file attachments.
We are looking forward to hearing from you.

Regards,
Damyan Bogoev
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Tags
General Discussions
Asked by
Mandy
Top achievements
Rank 2
Answers by
Damyan Bogoev
Telerik team
Share this question
or