You haven't shown us how you set up your DbContext and what your entity models look like so we're only guessing here. We can assume that you understand how EF works and that you followed along with the beginner's guide to getting data from EF. If you didn't follow that documentation then you need to start there. We cannot tell you everything you need to do to get data from EF in a forum post.
Assumed entities:
public class Preference
{
public int Id { get; set; }
public string Title { get; set; }
public bool Value { get; set; }
}
public class OrganizationPreference
{
public int OrganizationId { get; set; }
public int PreferenceId { get; set; }
public Preference Preference { get; set; }
public bool? Value { get; set; }
}
The query in EF.
//Get all preferences for an organization
var preferences = from a in context.OrganizationPreference
.Include(x => x.Preference)
where a.OrganizationId = 101
select new PreferenceDto {
OrganizationId = a.OrganizationId.ToString(),
PreferenceId = a.PreferenceId.ToString(),
PreferenceTitle = a.Preference.Title,
PreferenceValue = a.Value ?? a.Preference.Value
};
Assuming here that you set up your configuration such that OrganizationPreference
properly references Preference
table.