读取器关闭时无效尝试调用IsDBNull

时间:2014-07-16 11:18:44

标签: linq

我正在尝试使用Linq运行查询。有时查询成功运行有时会给我以下错误

"当阅读器关闭时,无效尝试调用IsDBNull"

我无法确定此问题的根本原因。如果有人知道,请帮我解决这个问题。 任何帮助都将受到高度赞赏。

lstitems = lstAllItems.Join(db.Users, i => i.UserId, u => u.UserID, (i, u) => new {
    i, u
}).GroupJoin(db.UserProfile, u => u.u.UserID, up => up.UserID, (u, up) => new {
    u, up
}).SelectMany(sm => sm.up.DefaultIfEmpty(), (sm, up) => new {
    sm, up
})
    .AsEnumerable().Select(s => new ItemList {
    Title = s.sm.u.i.Title,
    UserId = s.sm.u.i.UserId,
    ItemId = s.sm.u.i.ItemId,
    RoomId = s.sm.u.i.RoomId,
    Description = s.sm.u.i.Description,
    OriginalImagePath = s.sm.u.i.OriginalImagePath,
    IdeaBookCount = db.IdeaBook.Where(o => o.UserId == s.sm.u.i.UserId && o.IsDeleted == false).Select(x => x.IdeaBookId).Count(),
    OwnerUserId = s.sm.u.u.UserID,
    ownerIdStatus = s.sm.u.u.IdStatus,
    OwnerName = s.sm.u.u.UserType == (int) UserType.RenovateProfessional ? s.sm.u.u.CompanyName : s.sm.u.u.FirstName + " " + s.sm.u.u.LastName,
    OwnerUserName = s.sm.u.u.UserName,
    OwnerImg = s.sm.u.u.UserType == (int) UserType.RenovateProfessional ? Utilities.ImagePathForProfileForCompany(s.up == null || s.up.profileImg == null ? "" : s.up.profileImg) : Utilities.ImagePathForProfileForUser(s.up == null || s.up.profileImg == null ? "" : s.up.profileImg),
    OwnerCoverPic = s.sm.u.u.UserType == (int) UserType.RenovateProfessional ? Utilities.ImagePathForCoverImageForCompany(s.up == null || s.up.CoverImg == null ? "" : s.up.CoverImg) : Utilities.ImagePathForCoverImageForUser(s.up == null || s.up.CoverImg == null ? "" : s.up.CoverImg),
    OwnerPlace = s.sm.u.u.location == null ? "" : s.sm.u.u.location,
    IsContractor = s.sm.u.u.UserType == (int) UserType.RenovateProfessional ? true : false,
    OwnerNameHref = BaseUrl + (s.sm.u.u.UserType == (int) UserType.RenovateProfessional ? "Pro/" : "User/") + s.sm.u.u.UserName,
    CommentCount = db.ItemCounts.Where(u => u.ItemId == s.sm.u.i.ItemId).Select(x => x.CommentsCount).FirstOrDefault(),
    LikeCount = db.ItemCounts.Where(u => u.ItemId == s.sm.u.i.ItemId).Select(x => x.LikesCount).FirstOrDefault()
}).ToList();

1 个答案:

答案 0 :(得分:1)

您需要增加CommandTimeOut的值,如下所示: -

database.CommandTimeout = int.MaxValue;