[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I  use a IQueryable return

Posted on 2010-09-13
5
Medium Priority
?
1,427 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 2000 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

649 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