Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite记录已填充,但为空w/C_C#_Sqlite_Xamarin.forms - Fatal编程技术网

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

C# SQLite记录已填充,但为空w/C,c#,sqlite,xamarin.forms,C#,Sqlite,Xamarin.forms,我正在创建一个应用程序,允许你安排大学学期。 我的主窗体正确显示术语及其属性。 如果用户单击一个术语,它将打开一个新窗口并加载术语中的类。 “添加术语”页面上的列表在其主页面中显示一项,但其属性均为空 以主要形式出现时: protected override async void OnAppearing() { await _connection.CreateTableAsync<Term>(); await _connection.Cre

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

以主要形式出现时:

  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();
    }
在添加术语时出现:

 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:我很确定我解决了这个问题。在我的类对象的实现中,我没有将{get;set;}添加到未填充的字段。

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

您需要弄清楚数据是否确实丢失,或者UI是否只是没有正确显示数据。加载数据后,使用调试器检查courseList以确定它是哪一个。数据实际上丢失了。我检查了输出,唯一有效的数据点是IDsIn essense,您有字段,而不是属性。
 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();
    }