0
我有如何在LINQ方法和語法中選擇Distinct/Group通過child屬性?
類public class Parent
{
[Key]
public int ParentID { get; set;}
public virtual ICollection<Child> Childs { get; set; }
}
public class Child
{
[Key]
public int ChildID { get; set; }
public int Grade { get; set; }
public int ParentID { get; set; }
[ForeignKey("ParentID")]
public virtual Parent Parent { get; set; }
}
我需要的東西,相當於
SELECT
Child.Grade
FROM
Parent
INNER JOIN Child ON
Parent.ParentID = Child.ParentID
WHERE
Parent.ParentID = 1
GROUP BY
Child.Grade
而且
SELECT DISTINCT
Child.Grade
FROM
Parent
INNER JOIN Child ON
Parent.ParentID = Child.ParentID
WHERE
Parent.ParentID = 1
任何幫助將不勝感激。由於