我有一个数据库 - ScoreDB 和表 - 具有属性名称和分数的 ScoreTable。我想按降序显示分数:
t = from ScoreTable s in scoreDB.ScoreTable
orderby s.Score descending
select s;
行错误:
GameScoreCollection = new ObservableCollection<ScoreTable>(t);
«成员“BrainGainWP.ScoreTable.Score”没有支持的 SQL 翻译。»。 但如果命令名称一切正常:
t = from ScoreTable s in scoreDB.ScoreTable
orderby s.Name descending
select s;
表格代码:
[Table]
public class ScoreTable : INotifyPropertyChanged, INotifyPropertyChanging
{
[Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
}
private string _Name;
[Column]
public string Name
{
get
{
return _Name;
}
set
{
if (_Name != value)
{
NotifyPropertyChanging("Name");
_Name = value;
NotifyPropertyChanged("Name");
}
}
}
[Column]
private int _Score;
public int Score
{
get
{
return _Score;
}
set
{
if (_Score != value)
{
NotifyPropertyChanging("Score");
_Score = value;
NotifyPropertyChanged("Score");
}
}
}
最佳答案
您的私有(private)变量 Score
上有 [Column]
,而不是公共(public)变量:
private int _Score;
[Column]
public int Score
{
get
{
return _Score;
}
set
{
if (_Score != value)
{
NotifyPropertyChanging("Score");
_Score = value;
NotifyPropertyChanged("Score");
}
}
}
关于c# - Windows Phone 中的 SQL 查询表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14550162/