views:

31

answers:

1

Good Morning All,

I'm having a small conceptual problem with ADO.NET EF4 (and perhaps ORM in general) and I was hoping someone could help fill in the gaps in my knowledge.

In my example I have a normalised Database with two Tables: User & Company

User // UserId(PK), CompanyId(FK), FirstName, LastName

Company // CompanyId(PK), CompanyName

I have created an Entity Data Model to match these tables in my application.

I now need to display a list of Users along with their Company Name in a listbox control. I realise I can display a list of Users using:

DatabaseEntities db = new DatabaseEntities();
Listbox1.ItemSource = db.Users;

Obviously the problem here is that it will display the CompanyId field as oppose to the CompanyName.

My question is; What is the best approach to get at the CompanyName Field? Do I create a stored procedure to return a different record set? Create a new entity with the fields I require?

I can think of several approaches but I'm not sure which is best practice.

Any help is greatly appreciated!

+1  A: 

Figured it out, i wasn't aware you could specify bindings like:

<TextBlock Grid.Column="3" Padding="10,20,0,0" Text="{Binding Company.CompanyName}"/>