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 7632943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:45:17+00:00 2026-05-31T06:45:17+00:00

Im want to create a data structure for using within my MVC3 application. The

  • 0

Im want to create a data structure for using within my MVC3 application. The site holds videos uploaded by users, I want to be able of setting up a location for the video so later on you can search based on the country, region or city.

The modeling of those entities is not a big problem to me, my question is which class attribute should I use for my video entity.

public class Country
{
 int CountryId
 string CountryName
}

public class Region
{
 int RegionId
 string RegionName
 int FK_CountryId
}

public class City
{
 int CityId
 string CityName
int FK_CountryId
int FK_RegionId
}

……..

public class Video
{
int VideoId;
string VideoName;
**Location VideoLocation;**
}

**public class Location
{
int LocationId;
Country CountrId;
Region RegionId;
City CityId;
}**

My initial idea, but I think it is not a really good design since you can have 2 identical rows for a Location, where it should be ideal to keep a unique reference to Locations

What do you think in terms of good design and performance?

  • 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-31T06:45:19+00:00Added an answer on May 31, 2026 at 6:45 am

    That is everyone’s nightmare I guess. Well…at least that was my nightmare when designing one of the applications.

    Depending on your secenario you might keep countries, cities, regions as different entities. Everything is find with that approach until you want the user to select either country, region or city. Looks like you would need to have nullable fields, which is not really the best practice, because you would then have to fully rely on application logic to maintain data integrity.

    Example of that approach would be:

    public class Country
    {
        public string Code { get; set; } //country ID would not make sense in this approach
        public string Name { get; set; }
    }
    
    public class Region
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string CountryCode { get; set; } //1 region is assigned to only 1 country
    }
    
    public class City
    {
        public string Code { get; set; }
        public string Name { get; set; }
        public string RegionCode { get; set; } //1 city is assigned to only 1 region
    }
    

    It looks good, simple to understand but think about the table where you capture what’s been selected. If you only care about city (last item in dependency list), it’s all clear and fine.

    public class UserSelectionWithCityOnly
    {
        public string CityCode { get; set; }
    }
    

    Pretty easy and straight forward? Looks like it is.
    Consider the scenario where you can select either country,city or region….it get’s really messy:

    public class UserSelectionWithEitherSelected
    {
        public string? CityCode { get; set; }
        public string? RegionCode { get; set; }
        public string? CountryCode { get; set; }
    }
    

    well…you could always check if CityCode.HasValue, but from DB point of view that would be a nullable field, which can add dirty data (should be fine if you are not pedantic about having neat and clean DB)

    So they way I solve this was by creating one hierarchical table with parent item id :

    public class MySolutionForDestinations
    {
        public int DestinationId { get; set; } //primary key
        public int ParentDestinationId { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public DestinationLevel Level { get; set; }
    }
    
    public enum DestinationLevel
    {
        Country = 0,
        Region = 1,
        City = 2
    }
    

    it’s probably not the most elegant solution, but it works really well. In this approach you only care about DestinationId which can be a country Id, region Id or a city Id, so you would definitely avoid having dirty data and can implement 1 to 1 mapping.

    Hope this will be usefull

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

Sidebar

Related Questions

Data table structure is: id1,id2,id3,id4,... (some other fields). I want to create summary query
i want to create tabs according to data from MySQL database using php for
I want to create application which would display spatial data on Map. I'm thinking
I want to create a WinForm application that must draw data coming from a
I want to create modules to structure my NodeJS application, but I'm a little
I want to create light object data-package to pass between client and server applications.
I want to create a similar behavior to the data reader class but for
I want to create a struct from data harvested by line from a file.
I want to create search interface to search data from GAE datastore? Can i
I want to create a web service in ASP.NET that fetches data from a

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.