c# - Windows Phone 中的 SQL 查询表达式

标签 c#

我有一个数据库 - 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/

相关文章:

c# - sqlite 数据库在插入时被锁定

c# - Asp.Net Core 是否跨请求保留 CallContext?

c# - 从 C# 运行 Oracle 存储过程

c# - 如何比较两个字节数组

c# - IQueryable<> 不包含查询的定义 - 检查数据库中是否存在记录 C#

c# - "Publish Now"按钮不起作用,但构建 > 发布可以

c# - 使用依赖注入(inject) (Autofac) 并避免服务定位器模式

c# - 区域和路由

c# - "StyleCop "SA1300 未在 GlobalSuppressions.cs 类中抑制

c# - 在 C# 中读取 Excel xlsb 文件