Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.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中的子查询到Silverlight中的实体_C#_Linq_Entity Framework_Silverlight - Fatal编程技术网

C# Linq中的子查询到Silverlight中的实体

C# Linq中的子查询到Silverlight中的实体,c#,linq,entity-framework,silverlight,C#,Linq,Entity Framework,Silverlight,我想在我的第一个Silverlight项目中将此SQL查询转换为LINQ to实体,但我不知道如何转换,我从未使用过LINQ: select * from Tipo t, Unidad u where t.Clave = @Clave and t.Equipo = u.Equipo and u.IDUni in (select IDUni from Orden o where o.IDUni = u.IDUni and o.Clave = t.Clave) 谁来帮帮我吧这是一个加入,后面跟着

我想在我的第一个Silverlight项目中将此SQL查询转换为LINQ to实体,但我不知道如何转换,我从未使用过LINQ:

select * 
from Tipo t,
Unidad u
where t.Clave = @Clave
and t.Equipo = u.Equipo
and u.IDUni in
(select IDUni
from Orden o
where o.IDUni = u.IDUni
and o.Clave = t.Clave)

谁来帮帮我吧

这是一个
加入
,后面跟着一个
Where
。试着这样做:

public void DoStuff(IEnumerable<Tipo> t, IEnumerable<Unidad> u, IEnumerable<Orden> o)
{
    string clave = "something";
    var items = t
        .Join(u,                                                 // join to collection "u"
              trow => trow.Equipo,                               // "t" selector
              urow => urow.Equipo,                               // "u" join selector
              (trow, urow) => new { trow = trow, urow = urow })  // result selector
        .Where(item => item.trow.Clave == clave 
                  && o.Where(orow => orow.IDUni == item.urow.IDUni 
                         && orow.Clave == item.trow.Clave)
                     .Select(orow => orow.IDUni)
                     .Contains(item.urow.IDUni)
        );
}
public void DoStuff(IEnumerable t,IEnumerable u,IEnumerable o)
{
string clave=“某物”;
var项目=t
.Join(u,//加入集合“u”
trow=>trow.Equipo,//“t”选择器
urow=>urow.Equipo,/“u”连接选择器
(trow,urow)=>new{trow=trow,urow=urow})//结果选择器
.Where(item=>item.trow.Clave==Clave
&&o.Where(orow=>orow.IDUni==item.urow.IDUni
&&orow.Clave==item.trow.Clave)
.Select(orow=>orow.IDUni)
.Contains(item.urow.IDUni)
);
}

以下是sql查询的翻译。您是否需要特定的专栏?
选择*

var query = from t in context.Tipo
            from u in context.Unidad
            where t.Clave == clave
            where t.Equipo == u.Equipo
            where (from o in context.Orden
                   where o.IDUni == u.IDUni
                   where o.Clave == t.Clave
                   select o.IDUni).Contains(u.IDUni)
            select new { t, u };

我试过这个,两种方法都可以:

ObjectSet<Orden> ordenes = this.ObjectContext.Orden;
ObjectSet<Unidad> unidades = this.ObjectContext.Unidad;
ObjectSet<Tipo> tipos = this.ObjectContext.Tipo;

var query = from t in tipos
            from u in unidades
            where t.Clave == _clave
            where t.Equipo == u.Equipo
            where (from o in ordenes
                   where o.IDUni == u.IDUni
                   where o.Clave == t.Clave
                   select o.IDUni).Contains(u.IDUni)
            select new { t, u };
非常感谢你

McGarnagle和


Aducci

您如何访问Entityframework?在Silverlight项目中不能有实体模型对不起,但我不太明白您所说的,因为现在我所说的是:想象它一定是urow=>urow。Unidad@Cyndy如果是“Unidad”类型,就不应该是。lambda选择类型为“Unidad”的属性“Equipo”。噢!好的,我明白了,是Tipo.Equipo=Unidad.Equipo之间的连接吗
var query = from t in tipos
            from u in unidades
            from o in ordenes
            where t.Clave == _clave
            where t.Equipo == u.Equipo
            where o.IDUni == u.IDUni
            where o.Clave == t.Clave
            select t;