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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:16:50+00:00 2026-06-13T06:16:50+00:00

I’m having a problem with a C# MVC project in ASP.NET. The problem I

  • 0

I’m having a problem with a C# MVC project in ASP.NET.
The problem I have is with a category system: If one category has been added to a company, then you should not be able to add any category that is a parent (higher level in the hierarchy) than what’s already been added (since it’s already included in the search).

Now I have added this in the C# code already using this:

if (companyToUpdate.Category.Any(x => x.Parent.Any(z => z.ID == currentCategoryID))) {
    //already exists
}

Now the problem is that I would like to add this check as a stored procedure in the SQL Server database.

My structure looks like this:

Company (all companies)

 ID Title
1   StackOverflow

Category (all categories)

 ID Title
1   Website
2   Helpful site
3   Very helpful site

CategoryDetails (used to know parent/child of each category,
every category has a relationship to all of its parents)
(Website -> Helpful site -> Very helpful site)

Parent_ID   Child_ID
1           2
1           3
2           3

CompanyCategoryDetails (what categories have been added to this company?)

 Company_ID Category_ID
1           3

Now to the problem:
When you are trying to add a new line (1, 2) into CompanyCategoryDetails, it should be denied, since because you have already added Category_ID 3 to it, that means Category_ID 2 is already included which specified in the CategoryDetails table.

I started doing some check where I INNERJOIN the tables, but didnt get far before I realized it couldnt be done the way I was thinking.

  • 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-06-13T06:16:52+00:00Added an answer on June 13, 2026 at 6:16 am

    I think the check you are asking for is this:

    IF EXISTS(
    SELECT * 
    FROM    CompanyCategoryDetails CCD
    JOIN    CategoryDetails CD
            ON  CCD.Category_ID = CD.Child_ID
    WHERE   CCD.Company_ID = @Company_ID
    AND     (CD.Parent_ID = @Category_ID OR CD.Child_ID = @Category_ID))
    BEGIN
        --already exists
    END
    

    This will check for trying to add to a compnay (a) a parent category or (b) an existing category

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

Sidebar

Related Questions

I'm having a problem in an ASP.NET C# MVC project that we're doing. We're
I'm having a problem with an ASP.NET MVC application that I'm developing. I'm still
I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with
I'm using KnockoutJS with ASP.NET MVC, and I'm having a problem with broken bindings
I'm having an odd problem with asp.net MVC razor view. I want my model
I'm having a problem with ASP.NET MVC 1.0. The first time I access a
I am working on a mvc project, and having problem with json. i have
Yesterday I was having fully compiled ASP.NET MVC 3.0 project. Today when i opened
Say I have an application with the following structure. // ASP.NET MVC (Web Project)
Just started working with .NET and MVC(1). I'm having a problem wherein in my

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.