LINQ Returns Blank Results?

5 posts, 0 answers
  1. Garrett
    Garrett avatar
    23 posts
    Member since:
    Sep 2012

    Posted 06 May 2011 Link to this post

    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?
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 09 May 2011 Link to this post

    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.
  3. DevCraft banner
  4. Garrett
    Garrett avatar
    23 posts
    Member since:
    Sep 2012

    Posted 09 May 2011 Link to this post

    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
  5. Garrett
    Garrett avatar
    23 posts
    Member since:
    Sep 2012

    Posted 10 May 2011 Link to this post

    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?
  6. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 12 May 2011 Link to this post

    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.
Back to Top
DevCraft banner