I need a ColumnName of a table in EF which I have it’s ID.
My Tables are something like this :
Retailers
[RetailerId] [int] IDENTITY(1,1) NOT NULL,
[RetailerName] [varchar](50) NOT NULL,
[StateName1] [bit] NOT NULL,
[StateName2] [bit] NOT NULL,
[StateName3] [bit] NOT NULL,
States
[SId] [int] IDENTITY(1,1) NOT NULL,
[StateName] [varchar](50) Not Null
I receive an SId from a function and need to select all retailers which are located in that State.
Something like:
var listOfRetailers = (from m in db.Retailers where m.[a column that it's id is equal to SId] == true select m ).toList();
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.
EDIT
Technically this is a bad design. Coz you are making the assumption that your States table will have 3 records
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 calledStateName4in 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-manysituation (one state can have many retailers and one retailer can be in many states), the best approach would be to create3 tables (Retailer, State, RetailerState), where by
RetailerStatetable will play the role of mapping entries fromState,Retailertables