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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:53:13+00:00 2026-06-01T03:53:13+00:00

Having problems with the combining of two statements in a controller. Both statements work

  • 0

Having problems with the combining of two statements in a controller. Both statements work but cannot get them working as one element.

First statement is to show data for a user when his username matches the logged on usersname
This works fine.

public ViewResult Index()
    {
        var myrecords = db.Customers.Where(UserData => UserData.UserName.Equals
                (User.Identity.Name)).ToList();

        return View(myrecords);
    }

Second statement is for connecting tables and showing the data. This works fine

  var caradverts = db.CarAdverts.Include(c => c.BodyType).Include(c => c.Car).Include(c => c.Colour).Include(c => c.Customer).Include(c => c.EngineSize).Include(c => c.fuel).Include(c => c.SalesPlan).Include(c => c.Transmission).Include(c => c.year);



        return View(caradverts.ToList());

Now the trouble is connecting both statements into one so it only shows the data for the user logged on.

Any advice welcome

  • 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-01T03:53:14+00:00Added an answer on June 1, 2026 at 3:53 am

    How about this:

    var caradverts = db.CarAdverts
                       .Include(c => c.BodyType)
                       .Include(c => c.Car)
                       .Include(c => c.Colour)
                       .Include(c => c.Customer)
                       .Include(c => c.EngineSize)
                       .Include(c => c.fuel)
                       .Include(c => c.SalesPlan)
                       .Include(c => c.Transmission)
                       .Include(c => c.year)
                       .Where(c => c.Customer.UserName == User.Identity.Name)
                       .ToList();
    

    Do you really need all of these Include statements though? It looks like most of them refer to plain primitive properties and not related entities.

    Also because most likely in the first case you want data from a single user I would rewrite your query like this:

     var userRecord = db.Customers
                        .SingleOrDefault(u => u.UserName == User.Identity.Name);
    

    Then update your model/view accordingly to deal with a single Customer record and not a collection.

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

Sidebar

Related Questions

Im having problems with classpaths. I have used them before with import but I'm
Just like the title says I am having problems combining two classes. Altough this
I am having a problem combining two WHERE statements in the following SQL statement
Having problems compiling this class. I'm working through a book on java and this
I'm having problems compiling the following program. I'm using gcc -framework Foundation inherit8.1m and
I'm not an experienced C++ programmer and I'm having problems compiling. I've got a
I'm following the kernel tutorial from here im having problems compiling my files. i
I'm having some problems with g++ and the compiling process for a C/C++ program
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume

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.