Solved

How do I  use a IQueryable return

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now