c# - Linq query for left-join -


i have 3 tables:

* usersettingstype { general, userspecific) * usersettingsoption { currency:general, language:general, location:userspecific } * usersettingsvalue { currency:usd, location:us } 

if run sql query:

select ust.name type, uso.name option, usv.value value usersettingoption uso   inner join usersettingtype ust on ust.id = uso.type_id  left join usersettingvalue usv on usv.setting_type_id = uso.id 

output is:

type         | name      | value -------------------------------- general      | currency  | usd general      | language  | null userspecific | location  | 

how can convert above in linq format?

you can following:

var result = (form uso in context.usersettingoption               join ust in context.usersettingtype on uso.type_id equals ust.id               join usv in context.usersettingvalue on uso.id equals usv.setting_type_id tmpusv               lusv in tmpusv.defaultifempty()               select new               {                  type = ust.name,                   option = uso.name,                   value = lusv != null ? lusv.value : null               }).tolist(); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -