In this example :
using System;
using System.Collections.Generic;
using dbModel;
using System.Linq;
using System.Data.Entity.Infrastructure;
namespace WinApp
{
public partial class Form1 : Form
{
private dbEntities dbc;
public IQueryable<ARTIKLI> art;
public IQueryable<ART_GRUPE> grp;
public Form1()
{
InitializeComponent();
dbc = new dbEntities();
}
private void GetData()
{
art = from a in dbc.ARTIKLIs
select a;
grp = from g in dbc.ART_GRUPE
select g;
artikliBindingSource.DataSource = art.ToList();
artGrupeBindingSource.DataSource = grp.ToList();
}
private void Form1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
{
dbc.SaveChanges();
}
private void loadData_Click(object sender, EventArgs e)
{
this.GetData();
}
private void refresh_Click(object sender, EventArgs e)
{
dbc.Entry(grp).Reload();
artGrupeBindingSource.ResetBindings(false);
}
}
}
everything builds OK. But when I run and click Refresh button I get error :
The entity type DbQuery`1 is not part of the model for the current context
I am just trying to refresh data from store for grp
entity instance using DbContext
. I know I can convert DbContext
into ObjectContext
and then use Refresh
method, but
it should be possible to do the same with DbContext.Entry(entity).Reload();
Can someone explain my mistakes in the code above?