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

LINQ Returns Blank Results?

4 Answers 83 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Garrett
Top achievements
Rank 1
Garrett asked on 06 May 2011, 10:47 PM
Hello,

I am just starting to learn LINQ using OpenAccess ORM and I'm not able to get any results from a query.

Here is my query:

var query = (from syschoolstatus in c2000context.SySchoolStatus
                         select syschoolstatus);
             
            radGridView1.ItemsSource = query;

Now when I load the Silverlight page with radGridView1 on it, the gridview will show all of the columns associated with that table, but it never populates with any data.

I've double-checked that the login I'm using is correct and I can guarantee there is data in that table (about 107 rows).

Am I missing something obvious?

4 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 09 May 2011, 04:40 PM
Hello Garrett,

 What data service are you using to transport the data to your silverlight application? Basically the data services work in an asynchronous way which means that the result might not be available when the UI renders. This said your UI will render with an empty collection of objects (the query result) and will not refresh because the query result does not implement INotifyPropertyChanges. What you can do is either store your result in a collection that is implementing this interface (ex ObservableCollection) or subscribe to the completed event of your retrieve operation and bind your grid then. This way you can ensure that the read operation has finished working and your UI is up to date.

Kind regards,
Petar
the Telerik team
Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
0
Garrett
Top achievements
Rank 1
answered on 09 May 2011, 05:57 PM
Hi Petar,

I am using Telerik's OpenAccess ORM and I'm using a LINQ to SQL statement to query the data.

I'm still very new to Silverlight and C#. Could you possibly supply a generic sample of how a LINQ to SQL query can be used with an ObservableCollection?

Thanks,

Garrett
0
Garrett
Top achievements
Rank 1
answered on 10 May 2011, 04:40 PM
Here's what works for me:

LoadOperation<SySchoolStatus> loadOperation5 = c2000context.Load<SySchoolStatus>(c2000context.GetSySchoolStatusQuery());
            this.radGridView1.ItemsSource = loadOperation5.Entities;

Here's what doesn't work:

        public class SySchoolStatusTable
        {
            public int SySchoolStatusID { get; set; }
            public string Code { get; set; }
            public string Descrip { get; set; }
            public int SyCampusGrpID { get; set; }
            public int SyStatusID { get; set; }
            public bool SystemCode { get; set; }
            public bool Active { get; set; }
            public char ModFlag { get; set; }
            public int UserID { get; set; }
            public DateTime DateAdded { get; set; }
            public DateTime DateLstMod { get; set; }
            public long ts { get; set; }
            public char? NSLDSStatus { get; set; }
            public bool CrmSuppressFlag { get; set; }
        }
public MainPage()
        {
            InitializeComponent();
 
var query = (from syschoolstatus in c2000context.SySchoolStatus
                                                                  select new SySchoolStatusTable
                                                                    {
                                                                        SySchoolStatusID = syschoolstatus.SySchoolStatusID,
                                                                        Code = syschoolstatus.Code,
                                                                        Descrip = syschoolstatus.Descrip,
                                                                        SyCampusGrpID = syschoolstatus.SyCampusGrpID,
                                                                        SyStatusID = syschoolstatus.SyStatusID,
                                                                        SystemCode = syschoolstatus.SystemCode,
                                                                        Active = syschoolstatus.Active,
                                                                        ModFlag = syschoolstatus.ModFlag,
                                                                        UserID = syschoolstatus.UserID,
                                                                        DateAdded = syschoolstatus.DateAdded,
                                                                        DateLstMod = syschoolstatus.DateLstMod,
                                                                        ts = syschoolstatus.Ts,
                                                                        NSLDSStatus = syschoolstatus.NSLDSStatus,
                                                                        CrmSuppressFlag = syschoolstatus.CrmSuppressFlag
                                                                    });
 
ObservableCollection<SySchoolStatusTable> sysctable = new ObservableCollection<SySchoolStatusTable>(query);
 
this.radGridView1.ItemsSource = sysctable;
}

What am I doing wrong?
0
PetarP
Telerik team
answered on 12 May 2011, 04:45 PM
Hi Garrett,

 In the second scenario the SySchoolStatus collection is empty. You will have to execute the load query to load the items there. Note that you will be able to apply some linq filters to further narrow the result (the linq statement will be translated to sql and executed on the server).

Regards,
Petar
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
LINQ (LINQ specific questions)
Asked by
Garrett
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Garrett
Top achievements
Rank 1
Share this question
or