SQLite记录已填充,但带C#为空

时间:2020-06-21 12:26:39

标签: c# sqlite xamarin.forms

我正在创建一个允许您安排大学学期的应用程序。 我的主窗体正确显示术语及其属性。 如果用户单击一个术语,它将打开一个新窗口并加载该术语中的类。 “添加术语”页面上的列表按预期显示一项(在“主页”中添加),但其属性全部为空白。

出现在MainForm中

  protected override async void OnAppearing()
    {
        await _connection.CreateTableAsync<Term>();
        await _connection.CreateTableAsync<Class>();
        await _connection.CreateTableAsync<Assessment>();

        var termLists = await _connection.Table<Term>().ToListAsync();

        // Seed data if there are no Terms
        if (!termLists.Any())
        {
            // Seed Data
            var newTerm = new Term();
            newTerm.Title = "Term 1";
            newTerm.Start = DateTime.Now;
            newTerm.End = DateTime.Now;
            await _connection.InsertAsync(newTerm);
            termLists.Add(newTerm);

            var newCourse = new Class();
            newCourse.classTitle = "Capstone";
            newCourse.start = new DateTime(2019, 11, 12);
            newCourse.end = new DateTime(2019, 12, 18);
            newCourse.status = "Completed";
            newCourse.instructorName = "John Smith";
            newCourse.instructorPhone = "123-455-7789";
            newCourse.instructorEmail = "John.Smith@wgu.edu";
            newCourse.courseNotes = "Notes about the course";
            newCourse.term = newTerm.TermID;
            await _connection.InsertAsync(newCourse);

            Assessment newObjectiveAssessment = new Assessment();
            newObjectiveAssessment.title = "Test 1";
            newObjectiveAssessment.start = new DateTime(2019, 11, 18);
            newObjectiveAssessment.end = new DateTime(2019, 11, 21);
            newObjectiveAssessment.ClassID = newCourse.classID;
            newObjectiveAssessment.Assessments = "Objective";
            await _connection.InsertAsync(newObjectiveAssessment);

        }


        var courseList = await _connection.Table<Class>().ToListAsync();
        var assessmentList = await _connection.Table<Assessment>().ToListAsync();

        termList.ItemsSource = new ObservableCollection<Term>(termLists);
        studentTerms = termLists;

        base.OnAppearing();
    }

用户点击字词的事件处理程序:

   async private void termList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
    {
        int selectionIndex = e.SelectedItemIndex;

        await Navigation.PushAsync(new AddTerm(studentTerms[selectionIndex]));
    }

出现在添加词中:

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

        if (term != null)
        {
            var courseList = await _connection.QueryAsync<Class>($"SELECT * FROM Class WHERE term = '{term.TermID}'");
            _courses = new ObservableCollection<Class>(courseList);
            classList.ItemsSource = _courses;
            //DisplayAlert("Course Name", courseList[0].classTitle, "cancel");
        }
        base.OnAppearing();
    }

编辑: 我已按要求检查了课程列表,除了课程ID和学期ID之外,其他所有内容均为空。

Edit2:可以肯定我已经解决了这个问题。在我的Class对象的实现中,我没有将{get; set;}添加到没有填充的字段中。

1 个答案:

答案 0 :(得分:0)

我的问题是我没有在类对象的属性中添加{get; set;}。