From your comments I think this is what you are looking for. But design wise what you have done is bad. I will explain shortly.
var listOfRetailers;
if(SId == 1)
{
listOfRetailers = db.Retailers.select(r=> r.StateName1.Equals(true)).ToList();
}
else if(SId == 2)
{
listOfRetailers = db.Retailers.select(r=> r.StateName2.Equals(true)).ToList();
}
else if(SId == 3)
{
listOfRetailers = db.Retailers.select(r=> r.StateName3.Equals(true)).ToList();
}
EDIT
Technically this is a bad design. Coz you are making the assumption that your States table will have 3 records
1 - ACT
2 - NSW
3 - NT
For every state you are have a corresponding column in Retailers table StateName1, StateName2, StateName3
Lets say you want to introduce a 4th state (say 4 - VIC
). Now you will need to introduce a new column called StateName4
in your Retailers table. (by doing this there will be code level and DB level changes)
Also with the new columns you are introducing additional overheard of unused/ redundant data.
since this is a many-to-many
situation (one state can have many retailers and one retailer can be in many states), the best approach would be to create
3 tables (Retailer, State, RetailerState), where by RetailerState
table will play the role of mapping entries from State
, Retailer
tables
Retailer
---------
[RetailerId]
[RetailerName]
State
------
[SId]
[StateName]
RetailerState
--------------
[RetailerId]
[SId]