Solved

How do I  use a IQueryable return

Posted on 2010-09-13
5
1,416 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
  • 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replace &lt; with < 14 59
.Net Web Site IIS Web.Config Content-Security-Policy 1 66
Connection String 16 56
jQuery - following an example but can I save data server side? 20 49
It seems a simple enough task, yet I see repeated questions asking how to do it: how to pass data between two forms. In this article, I will show you the different mechanisms available for you to do just that. This article is directed towards the .N…
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 a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 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