Answer the question
In order to leave comments, you need to log in
How to filter result in multiple include entity framework 6?
Hello.
There is a set of relations of the following types.
There are many categories of attributes.
Each category has many attributes.
Each project has its own values for each attribute.
The result is a set of classes with such keys
public class Project : ModelBase<Project>
{
// Категории аттрибутов
private List<ProjectAttributeCategoryDictionary> projectAttributeCategoryDictionaries;
public List<ProjectAttributeCategoryDictionary> ProjectAttributeCategoryDictionaries
{
get { return projectAttributeCategoryDictionaries; }
set
{
projectAttributeCategoryDictionaries = value;
NotifyPropertyChanged(m => m.ProjectAttributeCategoryDictionaries);
}
}
// Аттрибуты со значениями
private List<Attributes> attributes;
public List<Attributes> Attributes
{
get { return attributes; }
set
{
attributes = value;
NotifyPropertyChanged(m => m.Attributes);
}
}
}
public class ProjectAttributeCategoryDictionary : ModelBase<ProjectAttributeCategoryDictionary>
{
private List<ProjectAttributeDictionary> attributeDictionaries;
public List<ProjectAttributeDictionary> AttributeDictionaries
{
get { return attributeDictionaries; }
set
{
attributeDictionaries = value;
NotifyPropertyChanged(m => m.AttributeDictionaries);
}
}
}
public class ProjectAttributeDictionary : ModelBase<ProjectAttributeDictionary>
{
private List<Attributes> attributes;
public List<Attributes> Attributes
{
get { return attributes; }
set
{
attributes = value;
NotifyPropertyChanged(m => m.Attributes);
}
}
}
public class Attributes : ModelBase<Attributes>
{
public virtual Project Project { get; set; }
public virtual ProjectAttributeDictionary ProjectAttributeDictionary { get; set; }
}
foreach (var cat in db.ProjectAttributeCategoryDictionaries.
Include(x => x.AttributeDictionaries.
Select(t => t.Attributes.
Where(y => y.Project.ProjectId == projectId))))
{
}
foreach (var cat in db.ProjectAttributeCategoryDictionaries.Include("AttributeDictionaries").Include("AttributeDictionaries.Attributes"))
{
foreach (var ad in cat.AttributeDictionaries.ToArray())
{
foreach (var adAttribute in ad.Attributes.ToArray())
{
if (adAttribute.Project.ProjectId != projectId)
{
ad.Attributes.Remove(adAttribute);
}
}
}
categoryDictionary.Add(cat);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question