Hi all.
I'm looking for a strategy for how to map a common scenario I see in a database at work. Note that it doesn't actually use City and State, I'm just using them as an example.
Table State:
Code:
StateID
StateDescription
Table CityType:
Code:
StateID
CityID
CityDescription
Mapping the State table could be simple, but mapping the City table might be more difficult. I cannot use the "CityID" column as a primary key, since it has duplicates (the string key "other" or "springfield" is used in multiple states).
There will be cases where other entities use these tables to reference states and cities, and sometimes it will just reference states. But, assume it will NEVER just reference cities, so we don't have to worry about that.
If I went with using two entities, the State entity is simple, but the City entity would have to have a composite key. I tried this one out first, but it seems if I have both the state and city entity in another entity (say, "Address"), then I'll have problems trying to save an "address" entity. Using this entity:
Address:
Code:
AddressID
StateID
CityID
and trying to save with a state entity (using StateID) and a city entity (using StateID and CityID) will give me this error:
Code:
System.Data.SQLite.SQLiteException: SQLite error
Insufficient parameters supplied to the command
The SQL shows that the "State" column name is being put into the insert statement twice. I'm not sure if this is work-aroundable, although I haven't explored the avenue much.
I don't think using one entity will work, because then the entity will only be able to look at one table or the other (unless I were to use "join" in the mapping, which I haven't done before, so not sure if I should look down that road).
Finally, there's the idea of making two simple entities, and a third "wrapper" entity that can be used to make sure that the city matches a state.
Thanks in advanced!