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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:18:23+00:00 2026-05-12T14:18:23+00:00

I’m prototyping my first MVC application, it’s a simple forum. I’ve done part of

  • 0

I’m prototyping my first MVC application, it’s a simple forum. I’ve done part of the domain model and I’m trying to figure out how to do something that’s pretty basic in SQL alone, but I can’t figure it out in my application. Here are my Entities:

[Table(Name="Users")]
public class User
{
    [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
    public int Id { get; set; }

    [Column] public string Username { get; set; }
    [Column] public string Password { get; set; }
    [Column] public string PasswordHash { get; set; }
    [Column] public string PasswordSalt { get; set; }
    [Column] public string FirstName { get; set; }
    [Column] public string LastName { get; set; }
    public List<Forum> AllowedForums { get; set; }
    [Column] public DateTime LastLogin { get; set; }
    [Column] public DateTime MemberSince { get; set; }
}

[Table(Name="Forums")]
public class Forum
{
    [Column(IsPrimaryKey=true, IsDbGenerated=true, AutoSync=AutoSync.OnInsert)]
    public int Id { get; set; }
    [Column] public int ParentId { get; set; }
    [Column] public string Title { get; set; }
    [Column] public string Description { get; set; }
    [Column] public bool IsGlobal { get; set; }
    [Column] public int DisplayOrder { get; set; }
}

I also have a linking table called AllowedForums that looks like:

userid  forumid
  1       4

In order to select the forums that a user is allowed to view and forums where IsGlobal == true I’d do this in SQL:

SELECT * FROM Forums
LEFT OUTER JOIN AllowedForums ON Forums.id = AllowedForums.Forumid
WHERE AllowedForums.Userid = 1
OR Forums.IsGlobal = 1

How should I populate the

public List<Forum> AllowedForums

field using C#/Linq to SQL?

Should AllowedForum be a value object with its own table mapping? That seems like overkill but I could easily join on it. I looked briefly at EntitySet but the simple example I saw didn’t seem to fit. It feels like there should be an elegant way to get a collection of Forum objects for each User, but I can’t come up with any. BTW, I’m new to C# & OO. I should also mention that since these are the early stages of the app, I’m open to changing the structure/relationships of the entities or tables if there’s a better approach I’m not seeing.

  • 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-12T14:18:24+00:00Added an answer on May 12, 2026 at 2:18 pm

    You should have another Entity class (probably should be internal) that mirrors your AllowedForums table in the database. Now I’m assuming your User table and your Forums table both have PK/FK relationships to this AllowedForums table. Therefore, there should be an internal property on the User class that looks like this:

    internal EntitySet<AllowedForums> AllowedForumsRelationships
    {
       get;set;
    }
    

    Or something like that. This should be on both the User and Forums class. Your AllowedForums class will have two properties on it. One for User and one for Forum. (If you use the LINQ to SQL designer, all this will happen for you automatically).

    Once you have that, if you want to get all the AllowedForums for a user you can do something like this:

        public IList<Forum> AllowedForums
        {
           get
           {
              var result = new List<Forum>();
              foreach(var relationShip in this.AllowedForumsRelationships)
              {
                 result.Add(relationShip.Forum);
                 return result;
              }
           }
        }
    

    This is some rough code I just banged out, and I’m not sure it’s 100% accurate, but I think you’ll get the idea. Basically you’re dealing with a many to many relationship which is always a pain.

    EDIT: I just messed with this idea with the Northwind Database with these tables:

    Orders
    OrderDetails
    Products

    There’s a many to many relationship there: An order can have multiple products, and a product can belong to many orders. Now say you want to get all products for an order:

    public partial class Order
    {
            public IList<Product> Products
            {
                get
                {
                    var list = new List<Product>();
                    foreach (var item in this.Order_Details)
                    {
                        list.Add(item.Product);
                    }
                    return list;
                }
            }
     }
    

    That works, so it should work in the scenario you’re talking about as well.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am trying to loop through a bunch of documents I have to put
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,

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.