2010-07-06 169 views
1

我正在尝试使用silverlight,wcf数据服务(在网站代码上)和Linq-to-Entities。我知道匿名类型不能在silverlight上工作,于是我创建了一个已知的类来检索一些信息。 (我知道这个查询不完全是智能的,但它只是一个例子),但它不起作用。有人可以帮助我?Silverlight linq-to-entities匿名类型问题

这是代码。

public class DataSummary 
{ 
    public DataSummary() { } 

    public int AccountID { get; set; } 

    public string Account { get; set; } 

    int accountID; 
    string account; 
} 

    var p = (from q in svc.Accounts 
       select new DataSummary() 
       { AccountID = (int) q.AccountID, 
        Account = q.Account1 
       }) as DataServiceQuery<DataSummary>; 

     p.BeginExecute(new AsyncCallback(r => 
     { 
      try 
      { 
       this.grid.ItemsSource = p.EndExecute(r).ToList(); 
      } 
      catch (Exception ex) 
      { 
       string message = ex.Message; 
      } 
     }), null); 

当我运行的例子,该错误信息是

ex.Message "An error occurred while processing this request." string 

它是如此有趣,因为它没有解释的问题。

在这个问题

Silverlight 4 Data Binding with anonymous types

他们说,我们可以使用匿名类型,但我怎么可以把“为化DataServiceQuery ..........?

而且

+0

'ex'是否有'InnerException',可能会更清楚地发现实际出错的地方?顺便说一句,我没有看到这里使用任何匿名类型。 – AnthonyWJones 2010-07-06 17:15:17

+0

真正的查询包括3或4个表格。所以我想做一些简单的事情 – user375863 2010-07-06 18:21:18

+0

ase \t“<?xml version = \”1.0 \“encoding = \”utf-8 \“standalone = \”yes \“?> \ r \ n \ r \ n \ r \ n 响应要求版本2的数据服务的MaxProtocolVersion被设置为DataServiceProtocolVersion.V1 \ r \ n“\t System.InvalidOperationException {System.Data.Services.Client.DataServiceClientException} – user375863 2010-07-06 18:26:17

回答

0

当安东尼告诉我关于内部异常,我就ProtocolVersion发现的错误。

public static void InitializeService(DataServiceConfiguration config) 
{ 
    config.SetEntitySetAccessRule("*", EntitySetRights.All); 

    //On the service. You have to add this line 
    config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2; 
} 

感谢安东尼。我不知道内excep存在。