Click here to Skip to main content
14,382,360 members
   

Database

 
QuestionRe: Fetch data Pin
ZurdoDev25-Oct-19 5:22
professionalZurdoDev25-Oct-19 5:22 
Questionc# 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 11:25
professionaljkirkerx22-Oct-19 11:25 
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 11:41
professionaljkirkerx22-Oct-19 11: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 11:00
professionalJoan M21-Oct-19 11:00 
AnswerRe: How do you separate in pages database results? Pin
David Mujica23-Oct-19 3:48
memberDavid Mujica23-Oct-19 3:48 
QuestionI have a column and i need to find in which table this column exists throughout whole DB Pin
Anandkumar Prajapati8-Oct-19 20:29
professionalAnandkumar Prajapati8-Oct-19 20: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 21:46
memberVictor Nijegorodov8-Oct-19 21: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 22:11
protectorJörgen Andersson8-Oct-19 22:11 
Questionvb.net connection to a firebird database Pin
Member 767827622-Sep-19 18:15
memberMember 767827622-Sep-19 18:15 
AnswerRe: vb.net connection to a firebird database Pin
Victor Nijegorodov22-Sep-19 21:12
memberVictor Nijegorodov22-Sep-19 21:12 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 12:06
memberMember 767827623-Sep-19 12:06 
GeneralRe: vb.net connection to a firebird database Pin
Member 767827623-Sep-19 17:16
memberMember 767827623-Sep-19 17:16 
GeneralMessage Closed Pin
1-Oct-19 16:26
memberhayac h1-Oct-19 16:26 
QuestionMoving from access DB to Oracle to calculate average upon request Pin
Member 1447460719-Sep-19 12:12
memberMember 1447460719-Sep-19 12:12 
AnswerRe: Moving from access DB to Oracle to calculate average upon request Pin
Gerry Schmitz19-Sep-19 13:26
mveGerry Schmitz19-Sep-19 13:26 
QuestionMySQL database Pin
Alboyz17-Sep-19 17:46
memberAlboyz17-Sep-19 17:46 
AnswerRe: MySQL database Pin
#realJSOP18-Sep-19 2:08
mve#realJSOP18-Sep-19 2:08 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 17:58
memberAlboyz18-Sep-19 17:58 
AnswerRe: MySQL database Pin
Mycroft Holmes18-Sep-19 13:44
memberMycroft Holmes18-Sep-19 13:44 
GeneralRe: MySQL database Pin
Alboyz18-Sep-19 17:58
memberAlboyz18-Sep-19 17:58 
QuestionDatabase suddenly slow Pin
Super Lloyd17-Sep-19 16:39
memberSuper Lloyd17-Sep-19 16:39 
AnswerRe: Database suddenly slow Pin
CHill6018-Sep-19 1:05
protectorCHill6018-Sep-19 1:05 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 21:47
memberSuper Lloyd18-Sep-19 21:47 
AnswerRe: Database suddenly slow Pin
Richard Deeming18-Sep-19 2:01
mveRichard Deeming18-Sep-19 2:01 
GeneralRe: Database suddenly slow Pin
Super Lloyd18-Sep-19 21:47
memberSuper Lloyd18-Sep-19 21:47 

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.