Using Entities classes with DataGridView

Using Entities classes with DataGridView

Postby mpovidlov » Thu 12 Mar 2009 00:54

It is very easy to display and edit a database table represented by Entity class in DataGridView:

Code: Select all
var context = new Entities();
dataGridView1.DataSource = context.EMPLOYEE;


But when one of the columns is an FK to another table (like Department) the DataGrid would display the whole Entity Department in that column. As a result it does not show anything. I am interested in the FK value (DepartmentID) which is still a part of Employee table. Is it possible to tell the DataGrid to display the DepartmentID instead of the whole Department?
Thanks
mpovidlov
 
Posts: 20
Joined: Tue 06 Jan 2009 00:34
Location: US

Postby AndreyR » Thu 12 Mar 2009 15:43

First of all, I advise you to include Department objects like in the following example:
Code: Select all
dataGridView1.DataSource = context.emp.Include("dept");

This will load Department object associated with Employee.
As for your question about the good way to display the loaded objects, unfortunately, it exceeds the bounds of our support.
AndreyR
Devart Team
 
Posts: 2919
Joined: Mon 07 Jul 2008 13:16


Return to dotConnect for Oracle