S
S
SomeManEa2020-12-12 16:18:45
Entity Framework
SomeManEa, 2020-12-12 16:18:45

How to implement queries in WinForms Entity Framework?

I need to display the query in the dataGridView, but I don’t know how to do it.
I’m looking on the Internet, and they write how to do it in the console, but I need it in WinForms, I tried to implement it in Winforms, but nothing happens.
At first I thought that it was possible to call a stored procedure that I create in MSSMS, but this did not work, because only found with database first even though my model is code first
Tried LinQ to Entities but that doesn't work either, what am I doing wrong?
Throws error CS1936 Could not find an implementation of the query pattern for source type 'DbSet'. 'Select' not found.

Here is the code

ClientContext db;

 private void button1_Click(object sender, EventArgs e)
        {
            var clients = (from Clients in db.Clientss select clients).ToList();
        }


ClientContext.cs

using System.Data.Entity;

namespace FurnitureBApp
{
    class ClientContext : DbContext
    {
        public ClientContext() : base("FurnitureDb")
        { }

        public DbSet<Clients> Clientss { get; set; }
        public DbSet<Orders> Orderss { get; set; }
        public DbSet<Furniture> Furnitures { get; set; }
        public DbSet<FurnitureType> FurnitureTypes { get; set; }

        
    }
}


There were thoughts about outputting a view to the application, but logically, it may not work either, since I can’t add a stored procedure

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Korotenko, 2020-12-12
@firedragon

Please ask if it's not clear.
https://docs.microsoft.com/ru-ru/dotnet/api/system...

private static int _interval = 60;
        private static DatabaseCtx _ctx = DatabaseCtx.Instance;
        public static BindingList<Data> Items { get; set; } = new BindingList<Data>();

public ExportGridForm()
        {
            InitializeComponent();
            ReloadData();
            bindingSource1.DataSource = Items;
        }

private void ReloadData()
        {
            Items.Clear();
            foreach (var data in _ctx.GetDatas()) Items.Add(data);
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question