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
Solved

How do I loop through and display the content of an entity list using a while loop.

Posted on 2015-01-09
4
89 Views
Last Modified: 2015-03-03
How do I loop through and display the formatted content of an entity list using a while loop.
There's more than one item in sample below.

For example:
NLAMEMEntities2 oe = new NLAMEMEntities2();
 oe.Test5.ToList().Where(x => x.t5ID == int.Parse(TextBox4.Text.ToString())).First();

Open in new window

0
Comment
Question by:bmanmike39
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 250 total points
ID: 40541699
I have sample code where data is uploaded to a combobox based on data from Entity Framework Table:
 
// CLASS LEVEL DATA VARIABLE
WSCGSoftwareEntities db = new WSCGSoftwareEntities();

 ' LOAD CUSTOMER EE
private void LoadCustomersEE()
{
	List<initialRowCust> Cs = (from c in db.tblCustomersorderby 
                c.FirstName + " " + c.LastNamenew initialRowCust 
                {
		    CustName = c.FirstName + " " + c.LastName,
		    CustomerID = c.CustomerID
	       }).ToList();

	cmbCustomerEE.DataSource = null;
	cmbCustomerEE.DataSource = Cs;
	cmbCustomerEE.DisplayMember = "CustName";
	cmbCustomerEE.ValueMember = "CustomerID";

}

Open in new window


The reason I posted, thinking you maybe wanting to cycle trough records possibly to populate a drop box.  If not, then it possibly could be used to do what you are asking for. Please tell me more about what is that you want to accomplish.

In this example, the combobox is uploaded such that displays the customer FName_LName combination. But, upon click, it gives you customer ID to help with your search.

But, if you want to cycle through names, then replace lines 15 - 18 with:

foreach (void name in Cs)
{
      MessageBox.Show(name.CustName);
}
0
 
LVL 63

Assisted Solution

by:Fernando Soto
Fernando Soto earned 250 total points
ID: 40541995
Hi  bmanmike39;

I think this should do what you want.

var enumerator = oe.GetEnumerator();

while( enumerator.MoveNext() )
{
    [DataType] currentEntity = enumerator.Current;
    // Where [DataType] is of the type in the collection.
    // Your code here using the current entity from the collection
}

Open in new window

0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40542278
in line 8, need to add single space to change

List<initialRowCust> Cs = (from c in db.tblCustomersorderby

to

List<initialRowCust> Cs = (from c in db.tblCustomers orderby
0
 

Author Closing Comment

by:bmanmike39
ID: 40643025
Thanks
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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