1

我正在关注演示网格编辑内联它可以工作但不会更改为数据库,它只会更改填充我接下来要做的事情的列表

这里的代码

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);
        }
    }
4

1 回答 1

0

这个例外是众所周知的,有很多帖子如何避免它。它也包含在文档中。

于 2012-11-11T07:05:38.550 回答