我使用RIA Services创建了一个简单的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;
答案 0 :(得分:1)
解决方案:
using System.ServiceModel.DomainServices.Client;
答案 1 :(得分:0)
您需要在单独的行上定义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));