Derek
Derek

Reputation: 1

Errors using a LINQ query in a Silverlight application

I am trying to consume the WCF services using Silverlight application in Sharepoint.

It's going to display all the data from a list in a grid. Somehow it is throwing a error.

Cannot convert lambda expression to type 'system.Delegate' because it is not a delegate type.

using the generic type 'system.collections.generic.ienumerable' requires 1 type arguments

SLprojectsCRUD2010WCF.sharepointservice.list1item' is a type but is used like a variable.

How can this be solved?

private SharePointService.SkinnyBlondeDataContext _context;

public MainPage()
{
    InitializeComponent();
    this.Loaded += new RoutedEventHandler(LayoutRoot_Loaded);
}

private void ShowProjects()
{
    // Declare the LINQ query
    var projectsQuery = (from p in _context.Tasks
                            select p) as DataServiceQuery<SharePointService.TasksItem>;
    // Execute the LINQ query
    projectsQuery.BeginExecute((IAsyncResult asyncResult) => Dispatcher.BeginInvoke(() =>
    {                // Runs in the UI thread
        // EndExecute returns
        IEnumerable < TasksItem > this.dataGridProjects.ItemsSource = projectsQuery.EndExecute(asyncResult).ToList();
    }), projectsQuery);
}

private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
{
    // Get the context
    _context = new SharePointService.SkinnyBlondeDataContext(
                new Uri("http://vanir0269/_vti_bin/listdata.svc", UriKind.Absolute));
    ShowProjects();
}

Upvotes: 0

Views: 193

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500855

Until your source code is formatted properly it'll be a pain to see what the LINQ problem is, but the lambda expression problem is easy: Dispatcher.BeginInvoke takes a Delegate, and lambda expressions can only be converted into specific delegate types. This is easy to fix:

projectsQuery.BeginExecute((IAsyncResult asyncResult) => {
    Action action = () => {
        // Code in here
    };
    Dispatcher.BeginInvoke(action, null);
});

Upvotes: 1

Related Questions