带有linq -to- sql DataContext的Silverlight和RIA服务——无法使用客户端linq查询
本文关键字:linq 查询 客户端 服务 RIA sql -to- DataContext Silverlight 带有 | 更新日期: 2023-09-27 18:09:07
我已经用RIA服务创建了一个基本的Silverlight应用程序。域服务类使用一个LINQ-to-SQL类作为它的DataContext。
在我的Silverlight应用程序中,这工作得很好:
CMSContext db = new CMSContext();
gridTest.ItemsSource = db.Files;
db.Load(db.GetFilesQuery());
但是我不能这样做,例如:
db.Load(from f in db.GetFilesQuery() where f.Id > 2 select f);
编译错误:
Error 5 The type arguments for method 'System.ServiceModel.DomainServices.Client.DomainContext.Load<TEntity>(System.ServiceModel.DomainServices.Client.EntityQuery<TEntity>)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:'SilverLight'Silverlight 4 Projects'RIATest2'RIATest2'MainPage.xaml.cs 35 4 RIATest2
Error 4 Could not find an implementation of the query pattern for source type 'System.ServiceModel.DomainServices.Client.EntityQuery<RIATest2.Web.File>'. 'Where' not found. C:'SilverLight'Silverlight 4 Projects'RIATest2'RIATest2'MainPage.xaml.cs 35 22 RIATest2
提示吗?
更新:
解决方案是添加以下内容:
using System.ServiceModel.DomainServices.Client;
解决方案:
using System.ServiceModel.DomainServices.Client;
您需要在单独的行上定义linq查询:
var query = from f in db.GetFilesQuery() where f.Id > 2 select f;
db.Load(query);
另一个选项是使用lambda表达式:
db.Load(db.GetFilesQuery().Where(f => f.Id > 2));