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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:00:25+00:00 2026-05-11T15:00:25+00:00

I currently have 3 separate tables : Course, Category, and CourseCategory. CourseCategory is the

  • 0

I currently have 3 separate tables : Course, Category, and CourseCategory. CourseCategory is the connection only having the CourseID and CategoryId. I need a way in LINQ-to-SQL to add a Category property to Course objects that abstracts past the multiple tables. We need to change the application to only allow one category, but we don’t want to change the database in case we need to switch it back later.

How can I add a property to Course that will get the first category in the CourseCategory table?

  • 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. 2026-05-11T15:00:25+00:00Added an answer on May 11, 2026 at 3:00 pm

    Just extend your Course entity with a new property. The following will expose the single category (not the CourseCatergory, but you can easily change that if you want the CourseCategory) assocciated with the course, return null if there is none and throw an exception if there is more than one.

    public partial class Course {    public Category Category    {       get { return this.CourseCategories.SingleOrDefault().Category; }    } } 

    You could also add a setter to make the property writable.

    UPDATE

    You should even use Single() instead of SingleOrDefault() if having no category assocciated is not allowed, too.

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

Sidebar

Related Questions

I currently have 4 tables. Product, Category, SubCategory, ProductSubCategory. Category has a OneToMany SubCategory
Is it possible to combine Underscore's filter and map? I currently have two separate
I have some the page elements split into separate visual blocks. I am currently
I currently have a message system which writes to two tables, sent and received
I currently have a separate database for every competition year and I know I
I currently have a single DataSet declared which contains 3 tables. For sake of
I have a project where I need to build a two tables in sql
So what I currently have is my tables in SQL, with table connecting different
I'm currently using Tank Auth on my project. I'd like to have separate logins
I have a form that calls on two separate models. My validation works correctly

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.