简体   繁体   English

Silverlight linq-to-entities匿名类型问题

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

I am trying to work with silverlight, wcf data services ( on the website code) and Linq-to-Entities. 我正在尝试使用Silverlight,WCF数据服务(在网站代码上)和Linq-to-Entities。 I know that anonymous types don't work on silverlight then I created a known class in order to retrieve some information. 我知道匿名类型在Silverlight上不起作用,然后我创建了一个已知的类以检索一些信息。 (I know the query it is not exactly intelligent, but It is only an example) but It is not working. (我知道查询不是完全智能的,但这只是一个例子),但是它不起作用。 can somebody help me??? 有人可以帮我吗???

this is the code. 这是代码。

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);

when I run the example, the error message is 当我运行示例时,错误消息是

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

it is so funny, because it is not explaining the problem. 这很有趣,因为它没有解释问题。

Also in this question 同样在这个问题上

Silverlight 4 Data Binding with anonymous types 具有匿名类型的Silverlight 4数据绑定

they said that we can used anonymous types, but then how can I put the "as DataServiceQuery.......... ?? 他们说我们可以使用匿名类型,但是我该如何将“ as DataServiceQuery ..........?

When Anthony told me about the inner exception. 当安东尼告诉我有关内部异常的信息时。 I discovered the error on the ProtocolVersion. 我在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;
}

Thanks Anthony. 谢谢安东尼。 I didn't know that the inner exception existed. 我不知道内部异常存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM