0
استفاده از view در entity
من یه ویو دارم به نام PatientSymptoms و وقتی میخوام توی دیتا گرید ویو بذارمش ارور میده کد رو پایین مینویسم ممنون میشم ایردشو بگید:
dgvNewVisitSymptoms.DataSource = se.PatientSymptoms.Where(x => x.PatientID == searchID);
ارورشم که میده اینه :
System.NotSupportedException was unhandled
HResult=-2146233067
Message=Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported. Instead populate a DbSet with data, for example by calling Load on the DbSet, and then bind to local data. For WPF bind to DbSet.Local. For WinForms bind to DbSet.Local.ToBindingList().
Source=EntityFramework
StackTrace:
at System.Data.Entity.Infrastructure.DbQuery`1.System.ComponentModel.IListSource.GetList()
at System.Windows.Forms.CurrencyManager.SetDataSource(Object dataSource)
at System.Windows.Forms.CurrencyManager..ctor(Object dataSource)
at System.Windows.Forms.BindingContext.EnsureListManager(Object dataSource, String dataMember)
at System.Windows.Forms.BindingContext.get_Item(Object dataSource, String dataMember)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.SetDataConnection(Object dataSource, String dataMember)
at System.Windows.Forms.DataGridView.set_DataSource(Object value)
at Sepanta4.frmMain.txtNewVisitID_TextChanged(Object sender, EventArgs e) in c:\Users\Hooman\Documents\Visual Studio 2012\Projects\DXApplication2\Sepanta4\Form1.cs:line 776
at System.Windows.Forms.Control.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.OnTextChanged(EventArgs e)
at System.Windows.Forms.TextBoxBase.WmReflectCommand(Message& m)
at System.Windows.Forms.TextBoxBase.WndProc(Message& m)
at System.Windows.Forms.TextBox.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
InnerException:
3 پاسخ
1
کد رو به صورت زیر تغییر بده:
dgvNewVisitSymptoms.DataSource = new System.ComponentModel.BindingList(se.PatientSymptoms.Where(x => x.PatientID == searchID).ToList());
0
ممنون بابت جواب ولی این دفع ارور زیرر رو میده:
Error 1 Using the generic type 'System.ComponentModel.BindingList<T>' requires 1 type arguments
2
برای BindingList نوع جنریک و مشخص کن:
BindingList<T>
جای T اسم کلاس Entity رو بنویس...