Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7629511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:51:14+00:00 2026-05-31T05:51:14+00:00

I have a MySQL database with tables for Items and for Stores , and

  • 0

I have a MySQL database with tables for Items and for Stores, and a lookup table ItemStores, like this:

CREATE TABLE IF NOT EXISTS Items (
    itemId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    description VARCHAR(256) NOT NULL DEFAULT '',
    priceBeforeTax DECIMAL(10,2) NOT NULL,
) DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS Stores (
    storeId INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    storeName VARCHAR(128) NOT NULL,
) DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

CREATE TABLE IF NOT EXISTS ItemStores (
    storeId INT NOT NULL REFERENCES Stores(storeId),
    itemId INT NOT NULL REFERENCES Items(itemId),
    quantity INT NOT NULL
) DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;

The application stores the Items and Stores in ObservableCollectionss of Item and Store object, and some WPF controls are bound to these ObservableCollectionss, like so:

public class Store
{
    public int storeId { get; set; }
    public string storeName { get; set; }

    public override string ToString()
    {
        return this.branchName;
    }
}
private static ObservableCollection<Store> _stores = new ObservableCollection<Store>();
public static ObservableCollection<Store> Stores
{
    get { return _stores; }
}


public class Item
{
    public int itemId { get; set; }
    public string description { get; set; }
    public decimal priceBeforeTax { get; set; }

    public override string ToString()
    {
        return this.description;
    }
}
private static ObservableCollection<Item> _items = new ObservableCollection<Item>();
public static ObservableCollection<Item> Items
{
    get { return _items; }
}

Now my dilemma centers on how to assign the ItemStores data. I am thinking about having a HashTable in each Item that maps storeID to the quantity of the item in each Store. Is there a better way to map it, assuming that I will be occasionally searching for an Item by its itemId? I’m already running a SELECT * FROM Items to populate the ObservableCollection, I fear that running another query to get the quantity from each store would really hammer MySQL. A JOIN won’t help as I do not know how many stores will be returned and returning multiple rows for the same item (one row for each store that carries it) will make it a pain to put the data into the ObservableCollection.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T05:51:16+00:00Added an answer on May 31, 2026 at 5:51 am

    I would not take that road. You will soon find yourself building an ORM instead of using one. Furhermore, reading whole database into memory collections is bad idea because it will become performance problem once you realize that your data is stale and start reloading everything.

    As for original question, ORM classes have collections of related children as properties, so you will not have to search for all of them – you will find a Store and read all ItemStore objects. If you need a list of an item in all stores, you will ask a database for that information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables in my mysql database: CREATE TABLE IF NOT EXISTS `RECIPES`
In a MySQL database I have two tables linked in a join. One table
I have a table Items which stores fetched book data from Amazon. This Amazon
I have a MySQL database with multiple tables, each of which have the same
I have a MySQL database with 60 tables. Most of the tables have primary
I have a MySQL database with a few (five to be precise) huge tables.
I have a MySQL database set-up in a hierarchy style. There are 4 tables
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
I have two tables in a MySql database: COUNTRY --------------- id, country_name and CITY
I have multiple tables in a mysql database and I am trying to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.