Solved

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

Posted on 2015-01-09
4
85 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 33

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 62

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 33

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

759 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

20 Experts available now in Live!

Get 1:1 Help Now