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

  • Home
  • SEARCH
  • 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 6678233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:13:05+00:00 2026-05-26T04:13:05+00:00

I am making an MVC 3 web application in asp.net. It is supposed to

  • 0

I am making an MVC 3 web application in asp.net. It is supposed to be like a little community where users can send messages to each other (and later on also to specified groups of people). So in my database I have the tables Users and Messages. A row in Messages (a message) contains both sender and receiver (a foreign key to the Users table) plus some other info such as title, send date and of course the message text.

When a user come to the index page for logged in users, I want to show all messages that have been sent to this user, or sent from this user. Therefore, when reading the messages from the Messages table I want to use a parameter, the id of the logged in user (which I can access in my controller). So I have the parameter but I don’t know how to use it when getting the results. I know there must be a way to do this correctly instead of putting in a bunch of sql and starting connections right in the code the ugly way.

As you maybe can see now, all the messages from the table will be retrieved and sent to the View for displaying it to the user.

The CommunityEntities line is part of the whole Entity Framework thing, not exactly sure how that stuff works yet, although I have been following some tutorials:

(Creating-an-entity-framework-data-model-for-an-asp-net-mvc-application)

(Mvc-music-store-part-1).

UserController.cs:

...

CommunityEntities db = new CommunityEntities();

public ActionResult Index()
    {
        var messages = db.Messages.ToList();
        return View(messages);
    }

...

CommunityEntities.cs:

public class CommunityEntities : DbContext
{
    public DbSet<User> Users { get; set; }        
    public DbSet<Message> Messages { get; set; }
}

EDIT: I did try that thing with db.Database.SqlQuery(…) but that seemed wrong, seeing as the point is to do this correctly and “neat”. This is for my education and my teachers are going to be picky at the structure of the application.

  • 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-26T04:13:06+00:00Added an answer on May 26, 2026 at 4:13 am

    You need a where clause:

    var messages = db.Messages.Where( m => m.SentById == id || m.SentToId == id ).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an ASP.NET MVC application, I'm making logic for Admin to accept or reject
I have built an ASP.NET mvc web application and it seems that some of
I created a web application in ASP.NET MVC and trying to call a controller
I have started developing a full-web application by using the ASP .NET MVC 3
Background I have a page on my ASP.NET MVC web app for users to
I am developing an ASP.NET MVC 3 web application using Razor and C#. I
I would like to build a new web application using ASP.NET MVC3 and MongoDB.
I have an ASP.NET MVC web application that makes REST style web service calls
I am currently in the process of making a new ASP.net MVC website, and
I'm having some trouble with ASP.NET MVC Beta, and the idea of making routes,

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.