Somebody edit the join table, because I can't remember the word for a table that contains only 2 foreign keys for 2 entities. Edit: I think it's called a link table?
The db-model looks like this DB-Model entities. And in the code for the models and DTO's, datadock has a List<Standard>
. So the code looks like this:
private List<DatadockDTO> GetDatadocksByDataportId(Guid id)
{
var query = from r in _ddRepository.GetIQueryable()
where r.DataportId == id
select new DatadockDTO
{
Id = r.Id,
Name = r.Name,
Standards = r.Standards //Error not possible, the only suggestion it gives is DataDockStandards
//I used to put GetStandardsByDatadockId(r.Id) here but there is another way apparently
};
List<DatadockDTO> datadocks = query.ToList();
return datadocks;
}
But somebody I work with told me Entity Framework allows you to do something like that. But I'm not sure where to look for.
The extra code I made how I thought it was supposed to work:
private List<StandardDTO> GetStandardsByDatadockId(int id)
{
var query = from r in _standardRepository.GetIQueryable()
where r.DataDockStandards.Any(dds => dds.DatadockId == id)
select new StandardDTO
{
Id = r.Id,
Name = r.Name,
StandardVersions = GetStandardVersionsByStandardId(r.Id)
};
List<StandardDTO> standards = query.ToList();
return standards;
}
private List<StandardVersionDTO> GetStandardVersionsByStandardId(int id)
{
var query =
from r in _svRepository.GetIQueryable()
where r.StandardId == id
select new StandardVersionDTO
{
Id = r.Id,
Name = r.Name,
};
List<StandardVersionDTO> versions = query.ToList();
return versions;
}
EDIT (next day): okay so apparently somehow I can select r.Standards somehow. I didn't change anything, I could suddenly just choose r.Standards without getting an error...