Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Problem loading data from Database

Hello, I am trying to create a window where I display a list of data out of a local MSSQL database. The database is hosted locally and I have added a EDMX model to the project. When I try and load data from my database with this code:

Code
using (var context = new Model.Entities())
            {
                _list = context.table.Select(p => p).ToList();
            }

It just gets stuck at that piece of code and does nothing.

Data Sources are set correctly (automatically)

Anyone? Thanks!
[Image: jYK9GP1.gif]
Download Example with simulation(fake table) of table:
mediafire[.]com/file/4f6b52yyovlu4en/demo.zip

Code
namespace demo
{
    public partial class Form1 : Form
    {
        private List<DemoClass> fakeTable = new List<DemoClass>();

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            fakeTable.Add(new DemoClass() { ID = 1, Name = "Hack", Lastname = "Forums" });
            fakeTable.Add(new DemoClass() { ID = 1, Name = "Hack 1", Lastname = "Forums 1" });
            fakeTable.Add(new DemoClass() { ID = 2, Name = "Hack 2", Lastname = "Forums 2" });
            fakeTable.Add(new DemoClass() { ID = 2, Name = "Hack 23", Lastname = "Forums 23" });
            fakeTable.Add(new DemoClass() { ID = 3, Name = "Hack 3", Lastname = "Forums 3" });

            LoadData(dgvDemo);
        }

        private void LoadData(DataGridView dgvDemo)
        {
            dgvDemo.DataSource=fakeTable.ToList();          

        }

        private void Filter(ComboBox cmbDemo, DataGridView dgv)
        {
            switch (cmbDemo.SelectedIndex)
            {
                case 0:
                    dgv.DataSource = fakeTable.Where(p => p.ID==p.ID).ToList();
                    break;
                case 1:
                    dgv.DataSource = fakeTable.Where(p => p.ID == 2).ToList();
                    break;
                case 2:
                    dgv.DataSource = (from t1 in fakeTable where t1.ID==2 select t1).ToList();
                    break;
                case 3:
                    dgv.DataSource = (from t1 in fakeTable where t1.ID == 2 select new { t1.ID,t1.Name}).ToList();
                    break;
                case 4:
                    dgv.DataSource = (from t1 in fakeTable where t1.ID == 2 select new { t1.ID, t1.Name,t1.Lastname }).ToList();
                    break;
                case 5:
                    dgv.DataSource = null;
                    dgv.DataSource = fakeTable.Select(p => p).ToList();
                    
                    break;

            }

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Filter(comboBox1,dgvDemo);
        }
    }
}

you write well encapsulation,your code seems to have written ok although I thought it was not in my first post..sorry for that... so I made a little demo to check...What can happen to the project if it is to do in MV or project that is separate from the database leyer in anather projects must copy connection string in bouth project in some case or try to update EF from v5 to v6 over nuget and reload EF in project...If none of the above help shere app config with us.
buy me a coffee eth:0x88621A52aa5Eb3b6503628369687111810186c58


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by KαѕρerAug 23, 2020 01:29 AM 3 209 Aug 23, 2020 01:29 AM
Last Post: ZestyVibes
[C#] by TunabishJun 17, 2018 10:20 PM 3 114 Jun 17, 2018 10:20 PM
Last Post: arvustpremium
[.NET] by EffexionApr 26, 2018 05:44 AM 0 124 Apr 26, 2018 05:44 AM
Last Post: Effexion