在负载测试 - "转换为值类型' System.Int32'失败,因为物化值为空"

时间:2014-05-30 07:15:13

标签: entity-framework linq-to-sql load-testing

当我们使用单个用户调试下面的代码时它工作正常。但是当我们尝试运行负载测试时,当用户数超过30时我们就会得到 "转换为值类型' System.Int32'失败,因为具体化值为null。结果类型的通用参数或查询必须使用可空类型。"异常。

这是我们获得例外的代码段。

  profile.AccessRights = (
                from t in entities.Opportunities
                join x in entities.OpportunityWorkloadGroups on t.OpportunityId equals x.OpportunityId into oppworkloads
                from ow in oppworkloads.DefaultIfEmpty()
                join m in entities.OpportunityWorkloads on ow.OpportunityWorkloadGroupId equals m.OpportunityWorkloadGroupId into oppworkloadmodules
                from om in oppworkloadmodules.DefaultIfEmpty()
                join y in entities.OpportunityUsers on om.OpportunityWorkloadId equals y.OpportunityWorkloadId into users
                from ou in users.DefaultIfEmpty()
                where (((t.LookupOpportunityStatu.Name.Equals(Constants.EstimationStatusCompletedName) || t.LookupOpportunityStatu.Name.Equals(Constants.OpportunityStatusDiscardedName)
                || t.LookupOpportunityStatu.Name.Equals(OSEConstants.OpportunityStatusCompletedWithDiscards)) && !t.IsRestricted) ? true : ou.User.Alias == null ? true : ou.User.Alias == alias)
                select new Microsoft.OneEstimator.DataAccess.Entities.AccessRights()
                {
                    MasterUserId = userId,
                    MasterUserRole = roleName,
                    OpportunityId = t.OpportunityId,
                    IsOpportunityOwner = t.OpportunityOwner == userId ? true : false,
                    IsRestricted = t.IsRestricted,
                    StatusName = t.LookupOpportunityStatu.Name,
                    OpportunityWorkloadId = ow.OpportunityWorkloads.Any(m => m.OpportunityWorkloadGroupId == ow.OpportunityWorkloadGroupId) ? ow.OpportunityWorkloads.FirstOrDefault(m => m.OpportunityWorkloadGroupId == ow.OpportunityWorkloadGroupId).OpportunityWorkloadId : 0,
                    EstimationId = ow.OpportunityWorkloadGroupId == null ? 0 : ow.IsActive == false ? 0 : ow.OpportunityWorkloadGroupId,
                    RoleName = ou.Role == null ? string.Empty : ou.User.Alias == alias ? ou.Role.RoleName : string.Empty,
                    HasRightsForWA = ow.WorkloadGroupVersion != null ? entities.WorkloadGroupUsers.Any(y => y.WorkloadGroupId == ow.WorkloadGroupVersion.WorkloadGroup.WorkloadGroupId && y.UserId == userId && y.Role.RoleName.Equals(OSEConstants.Estimator)) : true,
                    WorkstreamUserRoleName = ow.WorkloadGroupVersion != null ? entities.WorkloadGroupUsers.FirstOrDefault(y => y.WorkloadGroupId == ow.WorkloadGroupVersion.WorkloadGroup.WorkloadGroupId && y.UserId == userId).Role.RoleName : string.Empty
                }).ToList();

我想我对DefaultIfNull()做错了不确定。

0 个答案:

没有答案