Linq(ef)の添削の文法
6190 ワード
ふえる
追加
削除
//
using (StudentDbEntities db = new StudentDbEntities())
{
//
var avb = db.Student.Include("grade1").Select(s => new
{
id = s.id,
name = s.name,
age = s.age,
//gradnaem
//grade1 ef
gradnaem = s.grade1.gradename// grade1.
}).ToList();
dataGridView1.DataSource = avb;
}
追加
public static bool Add(Student student) {
using (StudentDbEntities db=new StudentDbEntities())
{
db.Student.Add(student);
return db.SaveChanges() > 0;
}
}
削除
public static bool delete(int id) {
using (StudentDbEntities db=new StudentDbEntities())
{
var sc = db.Student.FirstOrDefault(s => s.id == id);
db.Student.Remove(sc);
return db.SaveChanges()>0;
}
}