internal async Task <IEnumerable <VendorInfo> > GetVendorsAsync() { //IEnumerable<VendorInfo> model = await (from v in vendorRepository.Vendors // join p in productRepository.Products on v.VendorID equals p.VendorID // group p by new { p.Vendor.Name } into g // select new VendorInfo() // { // VendorName = g.Key.Name, // ProductCount = g.Count(), // FavoriteProductCount = g.Where(x => x.IsFavorite).Count() // }).ToListAsync(); //TODO: отображать вендора, даже если нет товаров IEnumerable <VendorInfo> model = await(from v in vendorRepository.Vendors join p in productRepository.Products.Include(x => x.Vendor) on v equals p.Vendor into GroupJoin from r in GroupJoin.DefaultIfEmpty() group r by new { r.Vendor.Name } into g select new VendorInfo() { VendorName = (g.Key.Name == null ? "XZ" : g.Key.Name), ProductCount = g.Count(), FavoriteProductCount = g.Where(x => x.IsFavorite).Count() }).ToListAsync(); return(model); }
private void LeftJoin() { var query = from person in MockData.People join pet in MockData.Pets on person.Id equals pet.OwnerId into GroupJoin from pet in GroupJoin.DefaultIfEmpty() select new { OwnerName = person.FirstName + " " + person.LastName, PetName = pet?.Name ?? string.Empty }; }
// ---------------------------------------------------------- // // -------------------- Page Management --------------------- // // ---------------------------------------------------------- // // --------------- Navigation --------------- // // ------------- Data retrieval ------------- // public static List <AuditProxy> AllLogEntries(DateTime fromDate, DateTime toDate, string tableName, string userID) { DateTime maxTime = toDate.AddDays(1); try { ProjectTileSqlDatabase existingPtDb = SqlServerConnection.ExistingPtDbConnection(); using (existingPtDb) { return((from ae in existingPtDb.AuditEntries join s in existingPtDb.Staff on ae.UserName.Replace(DbUserPrefix, "") equals s.UserID into GroupJoin from ss in GroupJoin.DefaultIfEmpty() where ae.ChangeTime >= fromDate && ae.ChangeTime < maxTime && ae.TableName == tableName && (userID == "" || userID == AllCodes || userID == ae.UserName.Replace(DbUserPrefix, "")) orderby ae.ChangeTime descending, ae.PrimaryValue ascending select new AuditProxy { ID = ae.ID, ActionType = ae.ActionType, User = ss ?? null, UserName = ae.UserName.Replace(DbUserPrefix, ""), ChangeTime = (DateTime)ae.ChangeTime, TableName = ae.TableName, PrimaryColumn = ae.PrimaryColumn, PrimaryValue = ae.PrimaryValue, ChangeColumn = ae.ChangeColumn, OldValue = ae.OldValue, NewValue = ae.NewValue } ).ToList()); } } catch (Exception generalException) { MessageFunctions.Error("Error retrieving log entry details", generalException); return(null); } }
public static void SetErrorLogEntries(DateTime fromDate, DateTime toDate, string type, string userID) { DateTime maxTime = toDate.AddDays(1); try { ProjectTileSqlDatabase existingPtDb = SqlServerConnection.ExistingPtDbConnection(); using (existingPtDb) { ErrorLogEntries = (from el in existingPtDb.ErrorLog join s in existingPtDb.Staff on el.LoggedBy equals s.UserID into GroupJoin from ss in GroupJoin.DefaultIfEmpty() where el.LoggedAt >= fromDate && el.LoggedAt <= maxTime && (type == AllRecords || el.ExceptionType.Replace("System.", "") == type) && (userID == "" || userID == AllCodes || userID == el.LoggedBy.Replace(DbUserPrefix, "")) orderby(DateTime) el.LoggedAt descending select new ErrorProxy { // ID = el.ID, CustomMessage = el.CustomMessage, ExceptionMessage = el.ExceptionMessage, ExceptionType = el.ExceptionType, TargetSite = el.TargetSite, LoggedAt = DbFunctions.CreateDateTime( // Have to do this 'long hand' to make sure we get distinct results ((DateTime)el.LoggedAt).Year, ((DateTime)el.LoggedAt).Month, ((DateTime)el.LoggedAt).Day, ((DateTime)el.LoggedAt).Hour, ((DateTime)el.LoggedAt).Minute, 0), LoggedBy = el.LoggedBy, User = ss ?? null, InnerException = el.InnerException } ).Distinct().ToList(); //foreach (ErrorProxy el in allErrors) //{ // DateTime dt = el.LoggedAt; // el.LoggedAt = new DateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, 0); //} //ErrorLogEntries = allErrors.Select(ae => new ErrorProxy //{ // CustomMessage = ae.CustomMessage, // ExceptionMessage = ae.ExceptionMessage, // ExceptionType = ae.ExceptionType, // TargetSite = ae.TargetSite, // LoggedAt = ae.LoggedAt, // LoggedBy = ae.LoggedBy, // User = ae.User, // InnerException = ae.InnerException //} //).Distinct().ToList(); } } catch (Exception generalException) { MessageFunctions.Error("Error retrieving error log entries", generalException); } }