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
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
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
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?
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