I build a student info app using Sqlite-net on Xamarin form if you can help me to follow the problem
I need to add info and display that info
but there is a problem in Fname
ObservableCollection<Student> data0 = new ObservableCollection<Student>(
Student.Where(s => s.Fname.StartsWith(searchName)).ToList());
this is my cod
namespace Aj.Service
{
public class Database
{
private readonly SQLiteAsyncConnection data;
public Database(string dbath)
{
data = new SQLiteAsyncConnection(dbath);
data.CreateTableAsync<Student>().Wait();
}
public async Task<List<Student>> GetStudents()
{
var student = await data.Table<Student>().ToListAsync();
if (student.Any())
{
await data.InsertAllAsync(objects: new Student[]
{
new Student{ID=1,Fname="حسان",Mname="صالح",Evaluation=5,Lname="خالد", },
new Student{ID=2,Fname="فلاح",Mname="سعيد",Evaluation=5,Lname="معيض", },
new Student{ID=3,Fname="ثابت",Mname="شافي",Evaluation=5,Lname="عايض", },
new Student{ID=4,Fname="مطر",Mname="مصلح",Evaluation=5,Lname="رغدان", }
});
}
return await data.Table<Student>().ToListAsync();
}
public ObservableCollection<Student> GetStudentsByName(string searchName)
{
ObservableCollection<Student> data0 = new ObservableCollection<Student>(
Student.Where(s => s.Fname.StartsWith(searchName)).ToList());
return data0;
}
}
}
CodePudding user response:
you are using a class name Student in the query
public ObservableCollection<Student> GetStudentsByName(string searchName)
{
var students = GetStudents();
ObservableCollection<Student> data0 = new ObservableCollection<Student>(
students.Where(s => s.Fname.StartsWith(searchName)).ToList());
return data0;
}
