Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Please help me with using FOR loop on Entity

$
0
0

Sorry to bother... I'm learning c# and found a problem that I don't know how to resolve... its about Entity connection to a local table... now I can loop using FOREACH... by curiosity I tried to make it using FOR instead... I get an ugly error... I can't refer to the item or member as Tabla[INDEX] as I usually do with Lists NOR can use the ElementAt(INDEX)... would you please tell me how to point to an specific item on my Table? thank for your help!

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LocalDbExample
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            conexionACME miConexion = new conexionACME();

            var Tabla = miConexion.Customers;

            for (int i = 0; i < Tabla.Count<Customer>(); i++)
            {
                Customer myCS = Tabla.ElementAt<Customer>(i); ------------------> HERE'S THE ERROR!! HOW TO GET ITEM?

                resultLabel.Text += $"{myCS.CustomerID}<br>";

            }

        }
    }
}




Viewing all articles
Browse latest Browse all 1698

Trending Articles