我正在关注演示网格编辑内联 它可以工作,但不能更改为数据库,它只会更改popolated的列表 我接下来要做什么
这里是代码
public static IList<Book> All()
{
IList<Book> result = (IList<Book>)HttpContext.Current.Session["Books"];
if (result == null)
{
HttpContext.Current.Session["Books"] = result =
(from book in new LibraryModel().Books
select new Book
{
PKiBookID=book.PKiBookID,
SBookName = book.SBookName,
SBookWriter= book.SBookWriter,
SDescription=book.SDescription,
BStatus=book.BStatus,
FKiBookType=book.FKiBookType
}).ToList();
}
return result;
}
public static Book One(Func<Book, bool> predicate)
{
return All().Where(predicate).FirstOrDefault();
}
public static void Insert(Book book)
{
//book.PKiBookID = All().OrderByDescending(p => p.PKiBookID).First().PKiBookID + 1;
All().Insert(0,book);
}
public static void Update(Book book)
{
Book target = One(p => p.PKiBookID == book.PKiBookID);
if (target != null)
{
target.SBookName = book.SBookName;
target.SBookWriter = book.SBookWriter;
target.SDescription = book.SDescription;
target.BStatus = book.BStatus;
target.BookType = new LibraryModel().BookTypes.Single(s => s.PKiBookTypeID == book.FKiBookType);
}
}