Click here to Skip to main content
15,892,809 members
Home / Discussions / Database
   

Database

 
AnswerRe: c# MongoDB Driver, find all products that contain a single brand name, and Group Distinct all category names, then get those categories. Pin
jkirkerx22-Oct-19 10:41
professionaljkirkerx22-Oct-19 10:41 
I came up with this and it works so far. A combination of Mongo and Linq.
Changed some categoryDistinct to productDistinct, better name.
I actually didn't think it would work.
var brandTask = _context.Brands.Find(b => b.Name == brandName).FirstOrDefaultAsync();

var productsFiltered = _context.Products.Find(b => b.Brand == brandName).ToList();
var productsDistinct = productsFiltered.GroupBy(c => c.Category).Select(x => x.FirstOrDefault());
var categoriesSelected = new List<Category>();
foreach (var product in productsDistinct)
{
    var cx = _context.Categories.Find(c => c.Name == product.Category).First();
    if (cx != null)
    {
        categoriesSelected.Add(cx);
    }
}

// Use filters here for a more complex search of products
var productFilter = Builders<Product>.Filter.Eq("Brand", brandName);
var productsTask = _context.Products.Find(productFilter).ToListAsync();

await Task.WhenAll(brandTask, productsTask);

return new GetBrandPage { Brand = brandTask.Result, Categories = categoriesSelected, Products = productsTask.Result };
If it ain't broke don't fix it
Discover my world at jkirkerx.com

QuestionHow do you separate in pages database results? Pin
Joan M21-Oct-19 10:00
professionalJoan M21-Oct-19 10:00 
AnswerRe: How do you separate in pages database results? Pin
David Mujica23-Oct-19 2:48
David Mujica23-Oct-19 2:48 
QuestionI have a column and i need to find in which table this column exists throughout whole DB Pin
Anandkumar Prajapati8-Oct-19 19:29
professionalAnandkumar Prajapati8-Oct-19 19:29 
AnswerRe: I have a column and i need to find in which table this column exists throughout whole DB Pin
Victor Nijegorodov8-Oct-19 20:46
Victor Nijegorodov8-Oct-19 20:46 
AnswerRe: I have a column and i need to find in which table this column exists throughout whole DB Pin
Jörgen Andersson8-Oct-19 21:11
professionalJörgen Andersson8-Oct-19 21:11 
Questionvb.net connection to a firebird database Pin
Member 767827622-Sep-19 17:15
Member 767827622-Sep-19 17:15 
AnswerRe: vb.net connection to a firebird database Pin
Victor Nijegorodov22-Sep-19 20:12
Victor Nijegorodov22-Sep-19 20:12 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 11:06
Member 767827623-Sep-19 11:06 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 16:16
Member 767827623-Sep-19 16:16 
QuestionMoving from access DB to Oracle to calculate average upon request Pin
Member 1447460719-Sep-19 11:12
Member 1447460719-Sep-19 11:12 
AnswerRe: Moving from access DB to Oracle to calculate average upon request Pin
Gerry Schmitz19-Sep-19 12:26
mveGerry Schmitz19-Sep-19 12:26 
QuestionMySQL database Pin
Alboyz17-Sep-19 16:46
Alboyz17-Sep-19 16:46 
AnswerRe: MySQL database Pin
#realJSOP18-Sep-19 1:08
mve#realJSOP18-Sep-19 1:08 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 16:58
Alboyz18-Sep-19 16:58 
AnswerRe: MySQL database Pin
Mycroft Holmes18-Sep-19 12:44
professionalMycroft Holmes18-Sep-19 12:44 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 16:58
Alboyz18-Sep-19 16:58 
QuestionDatabase suddenly slow Pin
Super Lloyd17-Sep-19 15:39
Super Lloyd17-Sep-19 15:39 
AnswerRe: Database suddenly slow Pin
CHill6018-Sep-19 0:05
mveCHill6018-Sep-19 0:05 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 20:47
Super Lloyd18-Sep-19 20:47 
AnswerRe: Database suddenly slow Pin
Richard Deeming18-Sep-19 1:01
mveRichard Deeming18-Sep-19 1:01 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 20:47
Super Lloyd18-Sep-19 20:47 
GeneralRe: Database suddenly slow Pin
Mycroft Holmes19-Sep-19 13:14
professionalMycroft Holmes19-Sep-19 13:14 
AnswerRe: Database suddenly slow Pin
Member 1240381729-Dec-19 23:35
Member 1240381729-Dec-19 23:35 
QuestionI need this windows odbc driver Pin
Member 1458760611-Sep-19 8:00
Member 1458760611-Sep-19 8:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.