View table by foreign key in C#

Asked

Viewed 432 times

2

So, I have a Pizzeria project and I have some tables, such as: Customer Registration, Employee Registration, Order Registration and etc. I’ve already created a Customer and Employees table and everything is OK. In the Order Registration table there are two fields that ask for the Employee ID and the Customer ID. Is it possible to select the Employee and Customer just by searching their names? Follow the link to better understand: http://i.imgur.com/txxt72B.png The foreign keys of the Order are: id_work and id_client.

  • Use the Join command in the query.

  • Post your code and what you’ve done, so it’s better to help you.

  • You are using Entity Framework?

  • @Anderson Trindade, my answer has solved your question ? Can I help you with something else ?

1 answer

1

You could join the Employee table with Customer and Order.

Ex:

 SELECT CLIENTE.NOME, CLIENTE.ID, FUNCIONARIO.NOME, FUNCIONARIO.ID, PEDIDO.ID
 FROM PEDIDO
 INNER JOIN CLIENTE
 ON CLIENTE.ID = PEDIDO.ID_CLIENTE
 INNER JOIN FUNCIONARIO.ID 
 ON  ON FUNCIONARIO.ID = PEDIDO.ID_FUNCIONARIO
 WHERE CLIENTE.NOME = 'LUÃ GOVINDA MENDES SOUZA'

However, I do not advise you to do this because CLIENT.NAME and EMPLOYEE.NAME are not table keys, being able to receive more than one record in the above query.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.