Reputation: 23
I have a problem when it comes to bind data to a grid view when this data retrieved from Entity framework 3.5 and the table being queried has foreign keys.
Usually when I bind a table to datagridview with LINQTOSQL and the table has a foreign key, go to edit the columns of the grid view and set the column Type to Combo box and then give it a separate data source and set the DisplayMember to the same value as the field of the foreign key. This used to display the value of the table that the foreign key is referring to.
When I started using EF I noticed that when you include a table in the EDM that has a foreign key and you also include the table that the foreign key points to in the EDM, Visual Studio automatically removes the foreign key from the entity and creates a relationship between the two entities.
This is creating a problem for me because I can't figure out how to show the value of the foreign key in the datagridview without going through each record and "manually" setting the value of the combox selected value...
Anyone has an idea of how to do this; I tried searching for hours on the internet but no luck... Any help is greatly appreciated.
Thank you,
Upvotes: 1
Views: 1394
Reputation: 23
I managed to find a way how to do this.
I first deleted all the associations created between the tables (Entities) in the EDM.
After this I created the scalar properties in the Entities with the same name as the foreign keys and then from then from the mapping details in the EDM mapped the foreign key field to the new scalar property created.
This worked for me, hope this can help someone else.
Thank you
Upvotes: 1