locked
Entity Framework - Lookup table RRS feed

  • Question

  • Hi all,

     

    I saw a screencast demonstrating potential future developments of the EDM designer:

    http://datajunkies.net/screencasts/EDM%20Designer%20Demo/EDM%20Designer%20Demo%20[noamba].html

     

    I am particularly interested in being able to combine a table and lookup table into one entity in this fashion.

    As in the example here my relationship would be one to many and not one to one like the contact to contact name split example provided elsewhere.

     

    Is this possible with the current CTP tool release, if not is it possible to adjust the edmx file manually to achieve this?

     

    Thanks in advance

     

    Martin

    Wednesday, November 14, 2007 11:46 AM

Answers

  • Currently, the Entity Framework does not directly support lookups. There are a couple of approaches to the problem. The following store definition:

     

    create table Address(aid int primary key, country_id int references Country(country_id), ...)

    create table Country(country_id int primary key, country_name nvarchar)

     

    can be mapped to a model:

     

    Address(AddressID int, Country navigation)

    Country(CountryID int, Name string)

    AddressCountry *:1

     

    Alternatively, you can write a custom mapping view (MSL:QueryView) or defining query (SSDL:EntitySet/DefiningQuery) to perform the lookup yourself. The query view would look something like this:

     

    select value Address(a.aid, c.country_name, ...)

    from storeContainer.Address as a join storeContainer.Country as c on a.country_id = c.country_id

     

    Thanks,

    -Colin

    Wednesday, November 14, 2007 1:34 PM

All replies

  • Currently, the Entity Framework does not directly support lookups. There are a couple of approaches to the problem. The following store definition:

     

    create table Address(aid int primary key, country_id int references Country(country_id), ...)

    create table Country(country_id int primary key, country_name nvarchar)

     

    can be mapped to a model:

     

    Address(AddressID int, Country navigation)

    Country(CountryID int, Name string)

    AddressCountry *:1

     

    Alternatively, you can write a custom mapping view (MSL:QueryView) or defining query (SSDL:EntitySet/DefiningQuery) to perform the lookup yourself. The query view would look something like this:

     

    select value Address(a.aid, c.country_name, ...)

    from storeContainer.Address as a join storeContainer.Country as c on a.country_id = c.country_id

     

    Thanks,

    -Colin

    Wednesday, November 14, 2007 1:34 PM
  • Thanks Colin for your response,

     

    I think I will just accept the default Navigation Property Entity construction and mapping for now.

    It would just be neater to have a single value property in the entity.

    Just curious, is this something that is on the radar for future developments?

     

    Regards

     

    Martin

    Thursday, November 15, 2007 1:14 PM