Herry Ng

Herry Ng

  • NA
  • 22
  • 9.8k

entity framework cast back to objectcontex

Jun 9 2012 12:29 AM
hi, i want to ask is there a method/workaround using refrextion or else to cast control.datasource back to objectcontex.

My code:
//ERP_AR is entity framework model
ERP_AR oOC = new ERP_AR();
List<MyTable> oList = oOC.MyTable.ToList();

BindingSource bs =new BindingSource();
bs.DataSource = oList;

datagridview1.DataSource=bs;


//The issue is could i cast back datagridview1.DataSource back to oOC
BindingSource bs_temp;
bs_temp = (BindingSource) DataGridView1.DataSource; //SUCCESS cast back to binding source

ObjectContex oOC_Temp;
oOC_Temp = (ObjectContex) bs_temp;// --> NOT SUCCESS Cannot cast


Thx



Answers (2)