LINQ 表达式在 LINQPad 中运行良好,但在 Silverlight 中返回空结果
这是 LINQ 中的简单左外连接(如 MS 示例)。 它在 LINQPad 中运行良好:
from x in Nevtars
join c in Tetsziks on x.NevtarID equals c.NevtarID into ctemp
from subc in ctemp.DefaultIfEmpty()
select new { x.Nev, subc.Tetszes }
The result:
-----------------
Nev Tetszes
Őszike 1
Őzike null
Pintyőke null
Regő null
Rezső null
Szellő null
Szellőke 2
Silverlight DomainSource 端的此表达式:
public IQueryable<MyP> GetTetszik()
{
var q2 = from x in this.Context.Nevtars
join c in this.Context.Tetszik on x.NevtarID equals c.NevtarID into ctemp
from subc in ctemp.DefaultIfEmpty()
select new MyP
{
Nev = x.Nev,
Tetszes = (subc == null ? 0 : (Int32)subc.Tetszes)
};
return q2;
}
public class MyP
{
[Key]
public string Nev { get; set; }
public int Tetszes { get; set; }
}
在“实体端”:
DomainService1 ctx2 = new DomainService1();
xxxGrid.ItemsSource = ctx2.MyPs;
var q2 = ctx2.GetTetszikQuery();
ctx2.Load(q2);
结果将是一个空网格...:(
请帮助我! 谢谢!
This is a simple left outer join in LINQ (like the MS example).
It works good in LINQPad:
from x in Nevtars
join c in Tetsziks on x.NevtarID equals c.NevtarID into ctemp
from subc in ctemp.DefaultIfEmpty()
select new { x.Nev, subc.Tetszes }
The result:
-----------------
Nev Tetszes
Őszike 1
Őzike null
Pintyőke null
Regő null
Rezső null
Szellő null
Szellőke 2
This expresion in Silverlight DomainSource side:
public IQueryable<MyP> GetTetszik()
{
var q2 = from x in this.Context.Nevtars
join c in this.Context.Tetszik on x.NevtarID equals c.NevtarID into ctemp
from subc in ctemp.DefaultIfEmpty()
select new MyP
{
Nev = x.Nev,
Tetszes = (subc == null ? 0 : (Int32)subc.Tetszes)
};
return q2;
}
public class MyP
{
[Key]
public string Nev { get; set; }
public int Tetszes { get; set; }
}
And in the "Entity side":
DomainService1 ctx2 = new DomainService1();
xxxGrid.ItemsSource = ctx2.MyPs;
var q2 = ctx2.GetTetszikQuery();
ctx2.Load(q2);
The result will be an empty grid... :(
Please help me!
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
域服务是否为
ItemsSource
提供了捕获更改的方法?如果没有,请在从数据库中获取数据后将其重新分配给ItemsSource
。Does the domain service provide a way for the
ItemsSource
to catch the changes? If not, reassign it to theItemsSource
after you grabbed the data from the database.