none
Association ? What's the goal ? RRS feed

  • Question

  • Hi,

    Here is my problem :
    I have a client table which contains a field called "CountryCode".
    I have a country table which contains fields called "Code" and "Name".

    So you understand the link between theses tables.

    In my code, I created a method called "getClients"  (from clt in ctx.Clients select clt) which return IEnumerable<Client>

    My question is how can I return IEnumerable<Client> with the name of the country instead of the countryCode ? or How can I acces to the name of the country when I have a IEnumerable<Client>?

    I don't really understand the goal of association except to say that there is a link between two tables.

    Thank you
    mercredi 15 juillet 2009 07:49

Réponses

  • Hi,

    Don't your country table have a CountryCode column ?

    You can simply make a join with the two tables.

    Example :

    SELECT c.*,cn.Name
    FROM dbo.client c
    INNER JOIN dbo.country cn
    ON c.CountryCode = cn.CountryCode
    WHERE c.client IN (...)

    ++
    MCDBA | MCITP SQL Server 2005 | LPI 1
    mercredi 29 juillet 2009 14:50
    Modérateur