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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:04:08+00:00 2026-06-09T01:04:08+00:00

This is a follow up question to this post I have two models: CarType.cs

  • 0

This is a follow up question to this post

I have two models:

CarType.cs

//
// Holds types of car - this has a one to many relationship with Car class
//
[Table("tType")]
public class CarType
{
    [Key]
    public int type_id { get; set; }
    public int dealer_id { get; set; }
    public string type_name { get; set; }
    public string type_desc { get; set; }
    public virtual ICollection<Car> Cars { get; set; }
}  


Car.cs

//
// Holds actual Cars
//

[Table("tCar")]
public class Car
{
    [Key]
    public int car_id { get; set; }
    public int dealer_id { get; set; }
    public int type_id { get; set; }
    public int car_order { get; set; }
    public string car_name { get; set; }
    public virtual ICollection<Rental> Rentals { get; set; }
    public virtual CarType CarType { get; set; }
}

I want to have a view model, where I can view car types, and how many of each car type I have within each Car Type class, so I’ve created a ViewModel:

public class SearchViewModel
{
    [Required]
    public DateTime From { get; set; }
    public int Nights { get; set; }
    public int dealer_id { get; set; }
    public IQueryable<CarType> CarTypes { get; set; }
    // CarTypes as above, has a one to many relationship with the class Car
}

Given a predeterminded list of actual cars (say preBookedCars), I want to remove the list of cars from the ViewObject so for example, if the model of CarType (including the one 2 many Cars) looked like this:

Mercedes (count = 3)
....Car 1
....Car 2
....Car 3
Ford (count = 3)
....Car 4
....Car 5
....Car 6
Citroen (count = 3)
....Car 7
....Car 8
....Car 9

Given a list of CARS, how would I EXCLUDE the list of cars from the CarType model – eg.

I have a list of: Car 1, Car 4, Car 8, Car 9 – so I would like the above model to show:

Mercedes (count = 2)
....Car 2
....Car 3
Ford (count = 2)
....Car 5
....Car 6
Citroen (count = 1)
....Car 7

I know it’s something along the lines of (pseudo LINQ):

var freeCars = (db context).CarTypes
                        .Cars
                        .Except(preBookedCars)

Thank you for any help,

Mark

  • 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-09T01:04:10+00:00Added an answer on June 9, 2026 at 1:04 am

    I’m not sure if this is what you’re looking for, but if you’re just trying to filter against the Cars collection in the CarType object, you can use something like this:

    var preBookedCars = new List<int> { 1, 5, 9 };
    var myCarType = new CarType();
    var filteredCars = myCarType.Cars.Where(c => !preBookedCars.Contains(c.car_id));
    

    This code can be adapted to be used where ever you need.

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

Sidebar

Related Questions

This is a follow-up question related to my previous post . Below is a
This post if a follow-up question to mt previous post: Android RESTful Web application
This is a follow-on question from the one I asked here . Can constraints
this is a follow-up question of mine. Suppose now I have a URL :
This is a follow-up question to this one . Consider this example: #include <iostream>
This is a kind of follow-up question to this post, where the coloring of
this is a follow-up question to my last one here: iOS: Initialise object at
This is a follow up question from another post but that post was answered.
This is a follow up of another question here on SO . I have
This is a follow up to this question: dropdownlist to combobox I have a

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.