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

GridLinqDataBinding problem

5 Answers 75 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 1
Matthew asked on 14 Aug 2012, 07:33 AM
Hi all,

I m trying to fill my radgrid's datasource by using linq to sql. Till now i successfully done it when i used only one table in queries. But when i wanted to join two tables i failed. Here is the method i used for data binding.

public RadGridSurveyAnswerPointsModel ViewSurveyAnswerPoints(int startIndex, int maximumRows,
string sortExpressions, string filterExpressions)
{
RadGridSurveyAnswerPointsModel model = new RadGridSurveyAnswerPointsModel();
IQueryable q = (from x in Context.cc_SurveyPoint
          join y in Context.CC_SurveyPointMain on x.SurveyMainPointID equals y.ID
          orderby x.Code
          select new DenemeClass
          {
               Id = x.ID,
               Code = x.Code,
               Description = x.Description,
               Sequence = x.Sequence,
               isActive = x.ISActive,
               IconId = x.IconId,
               Point = x.Point,
               SurveyMainPointId = y.Code
         });
            GridLinqBindingData data = RadGrid.GetBindingData(q, startIndex, maximumRows,
sortExpressions, filterExpressions);
            model.AnswerPointsList = data.Data.OfType<DenemeClass>().ToList();
            model.Count = data.Count;
            return model;
}

public class DenemeClass
    {
        public Guid Id
        {
            get;
            set;
        }
 
        public string SurveyMainPointId
        {
            get;
            set;
        }
 
        public string Code
        {
            get;
            set;
        }
 
        public string Description
        {
            get;
            set;
        }
 
        public int Point
        {
            get;
            set;
        }
 
        public int? IconId
        {
            get;
            set;
        }
 
        public int? Sequence
        {
            get;
            set;
        }
 
        public bool isActive
        {
            get;
            set;
        }
 
    }

It is compiled and at run time i get this error : DenemeClass' is not a valid metadata type for type filtering operations. Type filtering is only valid on entity types and complex types. 

It may not be related with radgrid but i guess you good people could help me. Thanks.

5 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 15 Aug 2012, 12:24 PM
Any solution ?
0
Andrey
Telerik team
answered on 16 Aug 2012, 12:23 PM
Hi,

Could you paste your complete page source code, so all the people who want to help you have better understanding of your case.

Basically the code you have provided is looking OK, but we need to sure that everything else is OK before making suggestions what would be causing the issue.

All the best,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Matthew
Top achievements
Rank 1
answered on 16 Aug 2012, 07:44 PM
I know this problem has no relation with telerik. But i m sure telerik team can handle it easily. Sorry for the disturbation.
 
Shortly what i am looking for is,

GridLinqBindingData data = RadGrid.GetBindingData(q, startIndex, maximumRows, 
sortExpressions, filterExpressions); 

how to cast data.Data to a custom class or list.

If i want to cast data.Data to an entity class there is no error :

GridLinqBindingData data = RadGrid.GetBindingData(q, startIndex, maximumRows, 
sortExpressions, filterExpressions);
            model.AnswerPointsList = data.Data.OfType<Context.cc_SurveyPoint 
>().ToList();

Above it works. But my example is a complex type(for the reason of join operation between two tables). So when i want to cast it to a custom class(DenemeClass) it gives the error : DenemeClass' is not a valid metadata type for type filtering operations. Type filtering is only valid on entity types and complex types. 


0
Matthew
Top achievements
Rank 1
answered on 20 Aug 2012, 03:13 PM
any advice ?
0
Matthew
Top achievements
Rank 1
answered on 21 Aug 2012, 03:42 AM
I solved it on my own.

To get rid of casting data to an entity type it should be ienumerable. data.Data does not have AsEnumerable() function but AsParallel() did the same for me.

model.AnswerPointsList = data.Data.AsParallel().OfType<DenemeClass>().ToList();

Finally, it works.
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Andrey
Telerik team
Share this question
or