SQL转LINQ转换问题

时间:2013-10-30 14:47:37

标签: c# sql linq

我有一个SQL查询,我知道它可以按预期工作。但我需要它是LINQ,我用它来与数据库进行交互。 SQL查询是:

    SELECT * FROM motorposition, experimentmotor, motors 
WHERE motorposition.motorid = experimentmotor.motorid 
AND experimentmotor.experimentid = 13 
AND motors.id = experimentmotor.motorid

我几乎没有使用LINQ的经验。甚至可以在LINQ中执行此操作吗?

1 个答案:

答案 0 :(得分:0)

代码将是这样的:

var results = from mp in yourcontext.motorposition 
    join e in yourcontext.experimentmotor on mp.motorid equals e.motorid
    join m in yourcontext.motors on e.motorid equals m.motorid
    where e.experimentid == 13
    select new {mp, e, m};