开发者

Silverlight and RIA Services with LINQ-to-SQL DataContext - Unable to use client side linq queries

开发者 https://www.devze.com 2023-04-06 03:08 出处:网络
I have created a bare bones Silverlight application with RIA Services. The domain service class uses a LINQ-to-SQL class as its DataContext.

I have created a bare bones Silverlight application with RIA Services. The domain service class uses a LINQ-to-SQL class as its DataContext.

In my Silverlight application this works fine:

CMSContext db = new CMSContext();

gridTest.ItemsSource = db.Files; 
db.Load(db.GetFilesQuery());

But I'm not able to do this, for example:

db.Load(from f in db.GetFilesQuery() where f.Id > 2 select f);

Compiler errors:

Error   5   The type arguments for method 'System.ServiceModel.DomainServices.Client.DomainC开发者_JAVA百科ontext.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

Any tips?

Update:

The solution is to add this:

using System.ServiceModel.DomainServices.Client; 


Solution:

using System.ServiceModel.DomainServices.Client; 


You need to define the linq query on a separate line:

var query = from f in db.GetFilesQuery() where f.Id > 2 select f;
db.Load(query);

Another option is to use a lambda expression:

db.Load(db.GetFilesQuery().Where(f => f.Id > 2));
0

精彩评论

暂无评论...
验证码 换一张
取 消