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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:00:49+00:00 2026-05-15T11:00:49+00:00

Edit: Both the answers below work. My problem was due to using the NHibernate

  • 0

Edit: Both the answers below work. My problem was due to using the NHibernate LINQ provider
like this:

from parks in Session.Linq<Park>()

instead of like this:

from parks in Session.Linq<Park().AsEnumerable()

I have a class called Park which has an of Amenities. I want to create a LINQ query that returns all Park objects which contain every Amenity in a list. So given:

List<Park> Parks(IList<Amenity> amenities)
{
   // I want a query that would look like this (if this worked)
   // return all Park objects that have all of the given amenities

  var query = from parks in db.Parks
              where parks.Amenities.Contains(amenities)
              select parks;
}

This query:

var query = from parks in Session.Linq<Park>()
    where amenities.All(a => parks.Amenities.Contains(a))
    select parks;

doesn’t work.

Here’s more of my code for context:

Mapping classes(I”m using Fluent NHibernate)

public ParkDBMap()
{
 Id(x => x.ParkId).Column("ParkId").GeneratedBy.HiLo("0").UnsavedValue(0);
 Map(x => x.Name, "Name");
 this.HasManyToMany<Amenity>(x => x.Amenities)
 .Table("ParksMaps_ParkAmenities")
.Cascade.SaveUpdate();
}


public AmenityDBMap()
{
 Id(x => x.AmenityId).Column("AmenityId").GeneratedBy.HiLo("0").UnsavedValue(0);
 Map(x => x.Name, "Name");
}

Test method:

public void ListParksByAmenity()
{
// Create Parks
int parkCount = 10;
CreateParks(parkCount);

// Create Amenities
Amenity restrooms = new Amenity();
restrooms.Name = "Restrooms";
ParksRepos.SaveAmenity(restrooms);

Amenity tennis = new Amenity();
tennis.Name = "Tennis Courts";
ParksRepos.SaveAmenity(tennis);

Amenity dogs = new Amenity();
dogs.Name = "Dogs Allowed";
ParksRepos.SaveAmenity(dogs);

// Add amenities to parks
IList<Park> parks = ParksRepos.Parks();

parks[0].AddAmenity(dogs);
parks[0].AddAmenity(tennis);
parks[0].AddAmenity(restrooms);
ParksRepos.SavePark(parks[0]);

parks[4].AddAmenity(tennis);
parks[4].AddAmenity(restrooms);
ParksRepos.SavePark(parks[4]);

parks[9].AddAmenity(restrooms);
ParksRepos.SavePark(parks[4]);

IList<Amenity> amenityList = new List<Amenity>() { restrooms};
List<Park> restroomsParks = ParksRepos.Parks(amenityList);

// three parks have restrooms
Assert.AreEqual(1, restroomsParks.Count);
Assert.AreEqual(parks[0].Name, restroomsParks[0].Name);

amenityList = new List<Amenity>() { dogs, tennis, restrooms };
List<Park> allAmenities = ParksRepos.Parks(amenityList);

// only one park has all three amenities
Assert.AreEqual(3, allAmenities.Count);

}

I have three tables. A “Parks” table, an “Amenities” table, and a many-to-many table that has two columns, a park id and an amenity id.

I’m having trouble wrapping my head around this. Anyone have any suggestions?

  • 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-15T11:00:49+00:00Added an answer on May 15, 2026 at 11:00 am
    List<Park> Parks(IList<Amenity> amenities)
    {   
      var query = from parks in db.Parks
                  where amenities.All(a => parks.Amenities.Where(sa => sa.ID == a.ID).Count() == 1)
                  select parks;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit I think there is some confusion, I am not using both of the
I have two view controllers in a tabbar which can both edit data. Therefore,
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT: See my answer below--> I am wanting to have a view that when
EDIT: iam using ajax to load text in my content that is why onload
EDIT : It turned out that this can only be done through an external
I got an interesting time-travel problem today, using the following code: for (int i
I have a weird problem with defining a mpi_type_contiguous and using mpi_gatherv later on.
e.g. so that these would both work - is it possible? (val,VAL2) = func(args)
I have modified the code in this question ,according to the answers there, in

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.