我需要生成这个数据模型(示例):
IList<FeatureGroupFeaturesDto> fcf = new List<FeatureGroupFeaturesDto>();
fcf.Add(new FeatureGroupFeaturesDto
{
FeatureGroup = new FeatureGroupDto { Id = 1, Name = "Interior" },
Features = new List<FeatureDto> {
new FeatureDto { Id = 7, Name = "Bancos Traseiros Rebatíveis" },
new FeatureDto { Id = 35, Name = "Computador de Bordo" },
new FeatureDto { Id = 38, Name = "Suporte para Telemóvel" }
},
});
fcf.Add(new FeatureGroupFeaturesDto
{
FeatureGroup = new FeatureGroupDto { Id = 2, Name = "Exterior" },
Features = new List<FeatureDto> {
new FeatureDto { Id = 13, Name = "Barras de Tejadilho" },
new FeatureDto { Id = 15, Name = "Retrovisores Aquecidos" },
new FeatureDto { Id = 16, Name = "Retrovisores Elétricos" }
},
});
基于实体:
public class Category
{
public int Id { get; set; }
public string Name { get; set; }
}
public class CategoryFeatureGroupFeature
{
[Key]
[Column("Category_Id", Order = 0)]
public int Category_Id { get; set; }
[Key]
[Column("FeatureGroup_Id", Order = 1)]
public int FeatureGroup_Id { get; set; }
[Key]
[Column("Feature_Id", Order = 2)]
public int Feature_Id { get; set; }
}
public class Feature
{
public int Id { get; set; }
public string Name { get; set; }
}
public class FeatureGroup
{
public int Id { get; set; }
public string Name { get; set; }
}
基本上,这个想法是获取按 FeatureGroup 分组的类别的所有特征。
编辑:
我正在尝试将信息放入此模型中:
public class FeatureCategoryFeatures
{
public FeatureGroup FeatureGroup { get; set; }
public IList<Feature> Features { get; set; }
}
如何使用 LINQ 和 Entity Framework 实现这一点?
谢谢。