我需要把ColorModel
发到网页上,每Shoe
个才能找到Stock
个.我想要一份ColorModel
强的子元素名单,但不知道怎么做.
下面是表类和模型类:
public class ColorModel
{
public int ShoeId { get; set; }
public int ColorId { get; set; }
public string? ColorName { get; set; } = null!;
public List<SizeModel> Sizes { get; set; }
}
public class SizeModel
{
public int? SizeId { get; set; }
public float? SizeValue { get; set; }
public int? Stock { get; set; }
}
public partial class ShoeVariant
{
public int ShoeVariantId { get; set; }
public int ShoeId { get; set; }
public int ColorId { get; set; }
public int SizeId { get; set; }
public int Stock { get; set; }
public virtual Color Color { get; set; } = null!;
public virtual Shoe Shoe { get; set; } = null!;
public virtual Size Size { get; set; } = null!;
}
public partial class Shoe
{
public int ShoeId { get; set; }
public string ShoeName { get; set; } = null!;
}
public partial class Size
{
public int SizeId { get; set; }
public float SizeValue { get; set; }
public virtual ICollection<ShoeVariant> ShoeVariants { get; set; } = new List<ShoeVariant>();
}
var result = (
from sv in _context.ShoeVariants
join s in _context.Shoes on sv.ShoeId equals s.ShoeId
join color in _context.Colors on sv.ColorId equals color.ColorId
join sz in _context.Sizes on sv.SizeId equals sz.SizeId
group sv by new {s.ShoeId, color.ColorId, color.ColorName} into g
select new ColorModel
{
ShoeId = g.Key.ShoeId,
ColorId = g.Key.ColorId,
ColorName = g.Key.ColorName,
Sizes = new List<SizeModel>
{
}
}).ToList();
我应该 for each SizeModel单独 Select 以获取列表吗?
Stock
值在ShoeVariants
中