【问题标题】:Silverlight linq-to-entities Anonymous type problemSilverlight linq-to-entities 匿名类型问题
【发布时间】:2010-07-06 14:51:44
【问题描述】:

我正在尝试使用 silverlight、wcf 数据服务(在网站代码上)和 Linq-to-Entities。我知道匿名类型在 silverlight 上不起作用,然后我创建了一个已知类来检索一些信息。 (我知道查询并不完全智能,但这只是一个例子)但它不起作用。谁能帮帮我???

这是代码。

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

他们说我们可以使用匿名类型,但是那我怎么能把“as DataServiceQuery.......... ??”

【问题讨论】:

  • ex 是否有一个 InnerException 可以更清楚地说明实际出了什么问题?顺便说一句,我在这里没有看到任何匿名类型的用法。
  • 真正的查询包括3或4个表。所以我想做一些简单的事情
  • ase "\r\n\r\n \r\n 响应要求使用协议的版本 2,但 MaxProtocolVersion 的数据服务设置为 DataServiceProtocolVersion.V1。\r\n" System.InvalidOperationException {System.Data.Services.Client.DataServiceClientException}

标签: c# silverlight linq-to-entities silverlight-4.0


【解决方案1】:

当安东尼告诉我内心的异常时。我在 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;
}

谢谢安东尼。我不知道内部异常存在。

【讨论】:

    猜你喜欢
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    • 2010-11-02
    相关资源
    最近更新 更多