internal async Task <List <ViewAccountProduct> > AccountProductsGetAsync(Guid accountId, Guid?systemId) { var sqlParams = new SqlParameter[] { accountId.ToSql("accountId"), systemId.ToSql("systemId") }; using (var cmd = Database.Connection.CreateCommand()) { cmd.CommandText = sqlParams.CommandText("[accounts].[pProductGetByAccountId]"); cmd.Parameters.AddRange(sqlParams); await Database.Connection.OpenAsync(); var reader = await cmd.ExecuteReaderAsync(); var products = ((IObjectContextAdapter)this).ObjectContext.Translate <ViewAccountProduct>(reader).ToList(); reader.NextResult(); var modules = ((IObjectContextAdapter)this).ObjectContext.Translate <ViewAccountProductModule>(reader).ToList(); Database.Connection.Close(); foreach (var product in products) { product.Modules = modules.Where(e => e.AccountProductId == product.AccountProductId).ToList(); } return(products); } }