簡體   English   中英

Silverlight linq-to-entities匿名類型問題

[英]Silverlight linq-to-entities Anonymous type problem

我正在嘗試使用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數據綁定

他們說我們可以使用匿名類型,但是我該如何將“ as DataServiceQuery ..........?

當安東尼告訴我有關內部異常的信息時。 我在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;
}

謝謝安東尼。 我不知道內部異常存在。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM