Assume this model and a key-value store that supports to take whole objects and not only scalar types:
class Country
{
public string Name { get; set; }
}
class Company
{
public string Key { get; set; }
public string Name { get; set; }
public Country Country { get; set; }
}
var bmw = new Company
{
Key = "bmw",
Name = "Bayerische Motoren Werke",
Country = new Country { Name = "Germany" }
};
var vw = new Company
{
Key = "vw",
Name = "Volkswagen",
Country = new Country { Name = "Germany" }
};
myStore.Put(bmw.Key, bmw);
myStore.Put(vw.Key, vw);
Questions:
- How would I deal with the relation between Company and Country without having redundant data?
- Company.Key: Is it a good idea to store the key inside the value? Technically it is redundant and therefore 'bad'. But after passing a 'Company' around in a multi layer application, I might need to remember the related key.