如何在Silverlight中添加/编辑DataServiceQuery LINQ投影?
Silverlight 5/WCF数据服务5.6.0/实体框架5/异步LINQ数据服务查询 如何在后续执行中重置/删除/取消缓存/删除DataServiceQuery LINQ查询中的投影 考虑以下代码:如何在Silverlight中添加/编辑DataServiceQuery LINQ投影?,linq,asynchronous,wcf-data-services,silverlight-5.0,Linq,Asynchronous,Wcf Data Services,Silverlight 5.0,Silverlight 5/WCF数据服务5.6.0/实体框架5/异步LINQ数据服务查询 如何在后续执行中重置/删除/取消缓存/删除DataServiceQuery LINQ查询中的投影 考虑以下代码: var query = ( from c in context.Customers select new Customers() { ID = c.ID, Name = c.Name, }
var query =
(
from c in context.Customers
select new Customers()
{
ID = c.ID,
Name = c.Name,
}
) as DataServiceQuery<Customers>;
query.BeginExecute((result) =>
Dispatcher.BeginInvoke(() =>
{
// process results from query...
// query.EndExecute(result).ToList();
}), null);
var查询=
(
在上下文中使用c
选择新客户()
{
ID=c.ID,
Name=c.Name,
}
)作为数据服务查询;
query.BeginExecute((结果)=>
Dispatcher.BeginInvoke(()=>
{
//处理查询的结果。。。
//query.EndExecute(result.ToList();
}),空);
在上面的代码片段中,我创建了一个具有两个投影(列)的LINQ查询,它将通过WCF数据服务返回ID和名称字段。这很好用;问题从下面开始
在稍后执行的另一个方法中,我有一个类似的查询来获取其他列/投影。但是,下面的LINQ查询返回与上面相同的结果集,并忽略其他列:
var query =
(
from c in context.Customers
select new Customers()
{
ID = c.ID,
Name = c.Name,
Age = c.Age, // additional columns returning null
Height = c.Height // additional columns returning null
}
) as DataServiceQuery<Customers>;
query.BeginExecute((result) =>
Dispatcher.BeginInvoke(() =>
{
// process results from query...
// query.EndExecute(result).ToList();
}), null);
var查询=
(
在上下文中使用c
选择新客户()
{
ID=c.ID,
Name=c.Name,
Age=c.Age,//其他列返回null
高度=c.高度//返回null的其他列
}
)作为数据服务查询;
query.BeginExecute((结果)=>
Dispatcher.BeginInvoke(()=>
{
//处理查询的结果。。。
//query.EndExecute(result.ToList();
}),空);
删除所有投影以返回所有列也失败;我只返回前面指定的初始ID和名称字段:
var query =
(
// No projections, just get ALL columns please!
from c in context.Customers
select c
) as DataServiceQuery<Customers>;
query.BeginExecute((result) =>
Dispatcher.BeginInvoke(() =>
{
// process results from query...
// query.EndExecute(result).ToList();
}), null);
var查询=
(
//没有投影,只需获取所有列即可!
在上下文中使用c
选择c
)作为数据服务查询;
query.BeginExecute((结果)=>
Dispatcher.BeginInvoke(()=>
{
//处理查询的结果。。。
//query.EndExecute(result.ToList();
}),空);
如何使DataServiceQuery对象放弃以前指定的投影?我没有选项执行首先返回所有列的查询。问题已解决:在执行任何LINQ查询之前,请在WCF数据服务上下文上设置以下合并选项:
context.MergeOption = MergeOption.OverwriteChanges;
相关信息: