0
SQLへのリンクを使用してレコードを挿入しようとしています。私は、提出する列データを含む新しいオブジェクトを作成する必要があることを知っています。しかし、どのようにオブジェクト名を特定するのですか?私はここで列メンバーを含む列データオブジェクト名の検索方法
に新しい「学生」オブジェクトを作成することはできませんよとレコードを挿入することはできません成功したレコードを削除することができていますが、
は私のコードは次のとおりです。で
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Student.Models;
namespace Student.Controllers
{
public class StudentController : Controller
{
//
// GET: /Student/
private IStudentRepository _repository;
public StudentController() : this(new StudentRepository())
{
}
public StudentController(IStudentRepository repository)
{
_repository = repository;
}
public ActionResult Index()
{
return View(_repository.ListAll());
}
public ActionResult RemoveStudent(int id)
{
StudentDataContext student= new StudentDataContext();
var std = student.Students.Single(h => h.StudentID == id);
student.Students.DeleteOnSubmit(std);
student.SubmitChanges();
return Content("Student " + id + " Removed");
}
public ActionResult AddStudent(int studentID)
{
StudentDataContext student= new StudentDataContext();
var std = student.Students.FirstOrDefault(h => h.StudentID == studentID);
if (std == null || std.StudentID < 1)
{
student.Students.InsertOnSubmit(std);
student.SubmitChanges();
return Content("Student " + id + " Added");
}
return Content("Student " + studentID + " is already present");
}
感謝Advance
すべての生徒をリストするインデックスビューを追加しました。私はすべての学生を降順でリストしたいと思います。それ、どうやったら出来るの? – user793468