public class MedicineTransation{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string name {get;set;}
public int age {get;set;}
public string grade {get;set;}
}
// StudentViewController
//Add student Record to student database.
btn_AddRecord.TouchUpInside += ((object sender, EventArgs e) => {
string folder = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
var db = new SQLiteConnection (System.IO.Path.Combine (folder, "student.db"));
db.CreateTable<MedicineTransation>();
var student = new Student {
name = studentName;
age = studentage;
grade = studentGrade;
};
db.Insert (student);
)};
//DetailedViewController
//Delete student Record to student database.
btn_DeleteRecord.TouchUpInside += ((object sender, EventArgs e) => {
// db.Insert (student); Insert Record into database.
// db.Delete (student); Delete Record from database.
}
想要从另一个viewcontroller访问相同的数据库。
答案 0 :(得分:0)
您可以实现存储库模式。
http://msdn.microsoft.com/en-us/library/ff649690.aspx
或者(如果该模式过度杀伤),那么您可以创建一个模型类,让它通过静态方法或单独的单例来管理自己。