【问题标题】:How to SQLite Query with constraint in xamarin forms cross platform C#?如何在 xamarin 表单跨平台 C# 中使用约束进行 SQLite 查询?
【发布时间】:2023-04-03 18:55:01
【问题描述】:

我正在 Xamarin.Forms 跨平台开发这个宠物项目。我在使用约束在 SQLite 中运行查询时遇到困难。我能够列出存储在表格中的所有元素。但是,我无法在表中查询具有相同 AccountNumber 的所有作业。我到处搜索,但找不到答案。任何人都可以提供一种可以帮助的工作方法,并在此先感谢您。

public SearchPage()
{
        InitializeComponent();

        _connection = DependencyService.Get<ISQLiteDb>   ().GetConnection();
}

private SQLiteAsyncConnection _connection;
private ObservableCollection<Job> _jobs;

public class NewJobTable
{
    [PrimaryKey]
    public string JobID { get; set; }

    public long AccountNumber { get; set; }
    public int JobNumber { get; set; }
    public DateTime DateCompleted { get; set; }
}

protected override async void OnAppearing()
{
    await _connection.CreateTableAsync<Job>();

    var jobs = await _connection.Table<Job>().ToListAsync();

    _jobs = new ObservableCollection<Job>(jobs);

    JobListView.ItemsSource = _jobs;

    base.OnAppearing();
}

【问题讨论】:

    标签: c# sqlite xamarin.forms cross-platform


    【解决方案1】:

    在 AccountNumber 上添加归档 (Where)

     var jobsWithSameAccountNumber = await _connection.Table<Job>()
                                      .Where(job => job.AccountNumber == accountNumberToCheck)
                                      .ToListAsync()
    

    【讨论】:

    • 工作就像一个魅力。非常感谢米伦
    猜你喜欢
    • 2017-05-09
    • 2019-05-15
    • 2018-06-20
    • 1970-01-01
    • 2015-10-20
    • 2018-06-15
    • 2020-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多