C# LINQ到SQL和LINQ到实体与静态和条件连接
我正在尝试将下面的C# LINQ到SQL和LINQ到实体与静态和条件连接,c#,entity-framework,linq,linq-to-sql,linq-to-entities,C#,Entity Framework,Linq,Linq To Sql,Linq To Entities,我正在尝试将下面的Join语句转换为LINQtoSQL或LINQtoEntity。我知道如何在两种实现中连接表;但是,我正在努力解决Join语句中的和子句 SELECT DISTINCT p.LastName, p.FirstName FROM dbo.Patient p INNER JOIN dbo.FormPat fp ON p.PatientID = fp.PatientID INNER JOIN dbo.TxCyclePhase tcp ON fp.Tx
Join
语句转换为LINQtoSQL或LINQtoEntity。我知道如何在两种实现中连接表;但是,我正在努力解决Join
语句中的和子句
SELECT DISTINCT
p.LastName,
p.FirstName
FROM
dbo.Patient p INNER JOIN dbo.FormPat fp ON p.PatientID = fp.PatientID
INNER JOIN dbo.TxCyclePhase tcp ON fp.TxCyclePhase = tcp.TxCyclePhaseID AND tcp.Type = 2
就LINQ to SQL而言,我有以下几点:
var query = (from p in Context.Set<Patient>().AsNoTracking()
join fp in Context.Set<PatientForm>().AsNoTracking() on p.Id equals fp.PatientId
join tcp in Context.Set<TxCyclePhase>().AsNoTracking() on new { fp.TxCyclePhaseId, seconProperty = true } equals new { tcp.Id, seconProperty = tcp.Type == 2 }
select new
{
p.FirstName,
p.LastName,
}).Distinct();
就LINQ to实体而言,我能够找到它。我仍然想知道如何在linqtosqltho中实现它
我在用电话。我的患者
对象看起来像:
public Patient()
{
Programs = new HashSet<Program>();
}
public virtual ICollection<PatientForm> Forms { get; set; }
public class PatientForm
{
public int FormId { get; set; }
public Patient CurrentPatient { get; set; }
public TxCyclePhase Phase { get; set; }
}
public TxCyclePhase()
{
this.FormPats = new HashSet<PatientForm>();
}
public int Id { get; set; }
public virtual ICollection<PatientForm> FormPats { get; set; }
而cyclepase
对象看起来像:
public Patient()
{
Programs = new HashSet<Program>();
}
public virtual ICollection<PatientForm> Forms { get; set; }
public class PatientForm
{
public int FormId { get; set; }
public Patient CurrentPatient { get; set; }
public TxCyclePhase Phase { get; set; }
}
public TxCyclePhase()
{
this.FormPats = new HashSet<PatientForm>();
}
public int Id { get; set; }
public virtual ICollection<PatientForm> FormPats { get; set; }
就LINQ to实体而言,我能够找到它。我仍然想知道如何在linqtosqltho中实现它
我在用电话。我的患者
对象看起来像:
public Patient()
{
Programs = new HashSet<Program>();
}
public virtual ICollection<PatientForm> Forms { get; set; }
public class PatientForm
{
public int FormId { get; set; }
public Patient CurrentPatient { get; set; }
public TxCyclePhase Phase { get; set; }
}
public TxCyclePhase()
{
this.FormPats = new HashSet<PatientForm>();
}
public int Id { get; set; }
public virtual ICollection<PatientForm> FormPats { get; set; }
而cyclepase
对象看起来像:
public Patient()
{
Programs = new HashSet<Program>();
}
public virtual ICollection<PatientForm> Forms { get; set; }
public class PatientForm
{
public int FormId { get; set; }
public Patient CurrentPatient { get; set; }
public TxCyclePhase Phase { get; set; }
}
public TxCyclePhase()
{
this.FormPats = new HashSet<PatientForm>();
}
public int Id { get; set; }
public virtual ICollection<PatientForm> FormPats { get; set; }
我想我的朋友会帮助你的。在这种情况下,规则6:在连接的每一侧创建一个匿名对象等于。我想我的方法会帮助您。在这种情况下,规则6:在连接的每一侧创建一个匿名对象等于。