Solved

How do I  use a IQueryable return

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Using MS Code on my Mac 6 47
Exception in Log4Net 1 20
Trouble connecting to SqlServer database 4 33
Copy/Clone an object. 9 15
Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

22 Experts available now in Live!

Get 1:1 Help Now