Solved

How do I  use a IQueryable return

Posted on 2010-09-13
5
1,425 Views
Last Modified: 2013-11-11
I am using Sillverlight 4 Business Application
The Domain Service returns a EntityQuery

DomainService
public IQueryable<NFe_C_emit> GetNFe_C_emit()
        {
            return this.ObjectContext.NFe_C_emit;
        }

My xaml
private void btnPesquisar_Click(object sender, RoutedEventArgs e)
        {

            dataGrid1.ItemsSource = db.GetNFe_C_emitQuery();
        }

ERROR
Cannot implicitly convert type 'System.ServiceModel.DomainServices.Client.EntityQuery<NFe.Web.NFe_C_emit>' to 'System.Collections.IEnumerable'

Questions:
1) How can I convert this to a IEnumerable<> for use in a DataGrid
2) How can I access row by row of this return.

Thanks


0
Comment
Question by:Plexo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 16

Accepted Solution

by:
kris_per earned 500 total points
ID: 33667259

You have to use LoadOperation in between:

LoadOperation<NFe_C_emit> loadOp = db.GetNFe_C_emitQuery();
dataGrid1.ItemsSource = loadOp.Entities;

// to access it row by row

List<NFe_C_emit> list =  loadOp.Entities.ToList();
foreach(NFe_C_emit item in list)
{
   
}

Also check out the following links:
http://msdn.microsoft.com/en-us/library/ff422488(v=VS.91).aspx
http://stackoverflow.com/questions/1486750/c-silverlight-with-entity-framework-change-return-type-on-autogenerated-entity
0
 

Author Comment

by:Plexo
ID: 33669304
The LoadOperation worked well for the DataGrid.
However for the List does not work.
The operation [for each] performed before bringing the record.
As I await the end of the operation to run [for each]?

<OK>
        private void btnPesquisar_Click(object sender, RoutedEventArgs e)
        {
            EntityQuery<NFe_C_emit> query =
                from c in _customerContext.GetNFe_C_emitQuery()
                select c;
            LoadOperation<NFe_C_emit> loadOp = this._customerContext.Load(query);
            dataGrid1.ItemsSource = loadOp.Entities;
        }

<NOT WORK>  
      private void btnSelecionar_Click(object sender, RoutedEventArgs e)
        {
            EntityQuery<NFe_C_emit> query =
                from c in _customerContext.GetNFe_C_emitQuery()
                select c;
            LoadOperation<NFe_C_emit> loadOp = this._customerContext.Load(query);
            List<NFe_C_emit> list = loadOp.Entities.ToList();
            foreach (NFe_C_emit item in list)
            {
                textBox1.Text = item.xNome;
            }
        }
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33669407
dataGrid1.ItemsSource = db.GetNFe_C_emitQuery().AsEnumerable<NFe_C_emit>();
0
 
LVL 8

Expert Comment

by:Gururaj Badam
ID: 33669409
for that to work you should have added System.Data.DataSetExtensions reference to your project
0
 
LVL 16

Assisted Solution

by:kris_per
kris_per earned 500 total points
ID: 33670096
To loop through the items after records are loaded, you can use Completed event of LoadOperation:

LoadOperation<NFe_C_emit> loadOp = this._customerContext.Load(query);

loadOp.Completed += (sender, args) => 
{ 
    List<NFe_C_emit> list = ((LoadOperation<Employee>)sender).Entities.ToList();
    foreach (NFe_C_emit item in list)
    {
       // use item object
    }
}; 

Open in new window

0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question