As an example, let's say you have a class like such
**Person**
int PersonID
string PersonName
BusinessLocation Locations
**BusinessLocation**
string city
string state
List<int> ZipCodes
(saying that the locations may exist in multiple zipcodes)
(also ignoring that zipcodes should be strings instead of ints, this is just an example)
Say that the locations of the Businesses exist in multiple zipcodes.
Now I am trying to pull back all the people in the person table, given a business zipcode.
For example, I want all the people who have a zipcode of 32567.
(Given a list of IDs, this works, I am trying to do the opposite, given one ID, I want a list of people)
public Person GetPersonsByBusinessZipCode(int zipcode)
{
List<Person> personList = this.GetAllQueryable().Where(x => x.Locations.ZipCodes.Contains(zipcode)).ToList();
}
This is Mapped Like such in Fluent.
HasMany<int>(x => x.ZipCodes)
.Table("BusinessLocationsZipCodes")
.KeyColumns.Add("BusinessLocationID")
.Inverse()
.Element("ZipCode")
.AsBag()
.Cascade.None()
.Cache.ReadOnly();
BusinessLocationZipCodes is just a reference table alluding that a BusinessLocation can have multiple ZipCodes, hence the HasMany.
Knowing that the reverse works, if I am given a list of ZipCodes and I am trying to find BusinessLocations contained in the list of zipcodes works (as long as the mapping is to a zipcode and not a List of zipcodes). Now I'm just trying to find the BusinessLocations given a zipcode.
If anyone has an answer, I would appreciate it.