私は、このSQLクエリがあります。のLINQとEntity Frameworkの、内部結合、グループ化、秩序メソッドの構文
SELECT
COUNT(PID.pid) AS Counted,
(SELECT TOP 1 Collect_id
FROM PID_Control
WHERE pid_controlY.org_pid = PID_Control.pid) as Collect_id
FROM
PID
INNER JOIN
PID_Control AS pid_controlY ON PID.pid = pid_controlY.pid
GROUP BY
pid_controlY.Collect_id, pid_controlY.org_pid
をそして私はLINQの中で同じことを書きたいが、私が処理するかどうかはわかりませんこのステートメント:
,(select top 1 Collect_id from PID_Control where pid_controlY.org_pid =
PID_Control.pid) as Collect_id
私はこのようにしましたか? =間違った線
var list = db.PID_Control
.Include(t => t.PID1)
.GroupBy(k => new { k.Collect_id })
.Select(c => new Grouped
{
Collect_id = ???
Counted = c.Select(q => q.PID1.pid1).Count(),
})
.ToList();
Linqでそれを作る方法?
クラス
public partial class PID_Control
{
public int pid_control_id { get; set; }
public Nullable<int> pid { get; set; }
public Nullable<int> Collect_id { get; set; }
public virtual PID PID1 { get; set; }
}
public partial class PID
{
public PID()
{
this.PID_Control = new HashSet<PID_Control>();
}
public int pid1 { get; set; }
public virtual ICollection<PID_Control> PID_Control { get; set; }
}
がここにあるだけでなく –
てきたが、今 – user4144972