static double?_GetValue(LinqMicajahDataContext dc, Guid MetricID, Guid?OrgLocationID, Guid?UomID, PeriodDate d, Guid OrganizationId, Guid InstanceId, out Guid?TotalUnitOfMessureID) { var values = (from m in dc.Metric join v in dc.MetricValue on new { MetricID, m.FrequencyID, Status = (bool?)true } equals new { v.MetricID, v.FrequencyID, v.Status } //join o in dc.EntityNodeFullNameView on v.OrgLocationID equals (Guid?)o.EntityNodeId join r in dc.FxGetRule(LinqMicajahDataContext.InstanceId) on new { InstanceId = (Guid?)v.InstanceId, MetricID = (Guid?)v.MetricID, OrgLocationID = (Guid?)v.OrgLocationID } equals new { r.InstanceId, r.MetricID, r.OrgLocationID } join l in dc.ViewHierarchyOrgLocation on new { InstanceId = (Guid?)v.InstanceId, OrgLocationID = (Guid?)v.OrgLocationID } equals new { l.InstanceId, OrgLocationID = l.SubOrgLocationID } join o in dc.ViewnameOrgLocation on new { InstanceId = (Guid?)v.InstanceId, OrgLocationID = (Guid?)v.OrgLocationID } equals new { o.InstanceId, o.OrgLocationID } where ( OrgLocationID == null || OrgLocationID == Guid.Empty || OrgLocationID == l.OrgLocationID //OrgLocationID == v.OrgLocationID || OrgLocationID == o.Parent1 || OrgLocationID == o.Parent2 || OrgLocationID == o.Parent3 || OrgLocationID == o.Parent4 || OrgLocationID == o.Parent5 ) && m.MetricID == MetricID && m.Status == true && v.Date >= d.Begin && v.Date < d.End select v).Distinct().ToList(); TotalUnitOfMessureID = null; if (values.Count < 1) { return(null); } double Sum = 0; bool ValueExist = false; TotalUnitOfMessureID = values[0].InputUnitOfMeasureID; for (int i = 1; i < values.Count; i++) { Guid?UID = values[i].InputUnitOfMeasureID; if (UID != TotalUnitOfMessureID) { TotalUnitOfMessureID = UomID; break; } } foreach (var v in values) { if (string.IsNullOrEmpty(v.Value)) { continue; } double SingleValue; try { SingleValue = double.Parse(v.Value, System.Globalization.NumberStyles.Any); } catch { continue; } if (TotalUnitOfMessureID != v.InputUnitOfMeasureID) { if (TotalUnitOfMessureID == null || v.InputUnitOfMeasureID == null) { continue; } double?ConvertedVal = Mc_UnitsOfMeasure.ConvertValue(SingleValue, (Guid)v.InputUnitOfMeasureID, (Guid)TotalUnitOfMessureID, OrganizationId); if (ConvertedVal == null) { continue; } SingleValue = (double)ConvertedVal; } ValueExist = true; Sum += SingleValue; } if (!ValueExist) { return(null); } return(Sum); }