Let's say I have three tables:
User
ID | Name =========== 1 | UserA ----------- 2 | UserB -----------
Setting
ID | Name | Default ========================= 1 | SettingA | ADefault ------------------------- 2 | SettingB | BDefault -------------------------
And
UserSetting
UserID | SettingID | Value ================================ 1 | 1 | Alice -------------------------------- 1 | 2 | Bob -------------------------------- 2 | 1 | AOverride --------------------------------
When I create my dbml file, it appropriately links User to UserSetting
and UserSetting
to Setting
based on the foreign keys set up in the database.
What I'm wondering is if its possible to coalesce back from UserSetting
to the Setting
table if the user hasn't specifically overridden the value in a way that makes sense.
Specifically, I'm looking for the following pseudo-code:
var user = MyDataContext.Users.SingleOrDefault(u => u.ID == 2);
foreach(var setting in user.UserSettings)
{
Console.Writeline(setting.ID + "|" + setting.Value);
}
To output something like this:
1 | AOverride 2 | BDefault
Without modification, user.UserSettings will only contain the values that have specifically been overridden, so it will only return:
1 | AOverride
Any ideas? Or could someone with more rep please help me rephrase this, since it probably isn't exactly clear? :)