日期:2014-05-20  浏览次数:21010 次

指定的 LINQ 表达式包含对与不同上下文关联的查询的引用
先贴代码

var pb = from d in pr.Purchases join b in br.Books
                                           on d.bookID equals b.bookID
                                           where d.pUserID == userID && d.sta != "2"
                                           orderby d.pTime descending
                                           select new PurchaseBook {
                                               pID = d.pID, 
                                               bookID = d.bookID,
                                               bookName = d.bookName,
                                               pUserID = d.pUserID,
                                               pUserName = d.pUserName,
                                               sta = d.sta,
                                               pTime = d.pTime,
                                               ZT = d.ZT,
                                               sUserID = d.sUserID,
                                               sUserName = d.sUserName,
                                               price = d.price,
                                               number = d.number,
                                               author = b.author,
                                               pub=b.pub
                                           };

br.Books和pr.Purchases是同一个数据库中的两张表,分别放到了两个类中,连接数据的时候是分别建立连接