0

I am working on this pet project in Xamarin.Forms cross platform. I am having difficulty running a query in SQLite using constraint. I am able to list all the elements stored on the table. However, I am unable to query the table for all the jobs with the same AccountNumber. I've searched everywhere but i can't find the answer. Can anyone provide a working method that would help please and thank you in advance.

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();
}

1 Answer 1

1

Add filering (Where) on AccountNumber

 var jobsWithSameAccountNumber = await _connection.Table<Job>()
                                  .Where(job => job.AccountNumber == accountNumberToCheck)
                                  .ToListAsync()
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm. Thank you so much Milen

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.