Solved

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

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

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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!
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …
This is an introductory video for CloudBerry Managed Backup. You will learn how to sign up with the service and get started in a few minutes.

911 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

21 Experts available now in Live!

Get 1:1 Help Now