Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# LINQ到SQL和LINQ到实体与静态和条件连接_C#_Entity Framework_Linq_Linq To Sql_Linq To Entities - Fatal编程技术网

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:在连接的每一侧创建一个匿名对象
等于