none
need help in creating association RRS feed

  • Question

  • Hi,

    i am beginner in entity framework.

    I am confused in creating association in EF although i have a concept.

    Suppose there is person , vehicle , sales table.

    1 sale have only 1 person and 1 vehicle

    but 1 vehicle , and 1 person can be included on many sales.

    so how i can define a relation . association in EF.

    currently i have done , 1toM in person to sale - and 1T1 relation in sale vehicle relation. Is it fine based on above senerio ?

    Thanks

    Wednesday, August 22, 2012 9:16 AM

Answers

  • Hi Shan khan,

    Welcome to MSDN Forum.

    Based on your post, 1 sale have only 1 person and 1 vehicle, 1 vehicle and 1 person can be included in many sales. This means, 1 person and 1 vehicle can belong to many sales, so the relationship should be: person : sale => 1 : n, vehicle : sale => 1 : n.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Shan Khan Monday, August 27, 2012 9:12 AM
    Thursday, August 23, 2012 1:45 AM
    Moderator
  • Hi Shan khan,

    There're 3 mapping strategy in Entity Framework.

    1. TPT - One model is mapped to one database table. In this strategy, every models must be mapped. (eg. model: A,B,C database table: A,B,C);

    2. TPH - When some models have hierarchy relationships, all the child models will be mapped to one database table. (eg. parent model: A, child models: B,C  database table: A)

    3. TPC - When some models have hierarchy relationships, each child models will be mapped to independent database tables and all the database tables contain the property of the parent model. (eg. parent model: A, child models: B,C  database table: B,C)

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Shan Khan Monday, August 27, 2012 9:10 AM
    Monday, August 27, 2012 1:56 AM
    Moderator

All replies

  • Hi Shan khan,

    Welcome to MSDN Forum.

    Based on your post, 1 sale have only 1 person and 1 vehicle, 1 vehicle and 1 person can be included in many sales. This means, 1 person and 1 vehicle can belong to many sales, so the relationship should be: person : sale => 1 : n, vehicle : sale => 1 : n.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Shan Khan Monday, August 27, 2012 9:12 AM
    Thursday, August 23, 2012 1:45 AM
    Moderator
  • thanks i have completed model. but still havent generated a database from it. I getting this warning for all the tables of the model :

    Warning 2 Error 11007: Entity type 'Person' is not mapped.

    is it mean i need to map it to database ? 

    Sunday, August 26, 2012 12:54 PM
  • Hi Shan khan,

    There're 3 mapping strategy in Entity Framework.

    1. TPT - One model is mapped to one database table. In this strategy, every models must be mapped. (eg. model: A,B,C database table: A,B,C);

    2. TPH - When some models have hierarchy relationships, all the child models will be mapped to one database table. (eg. parent model: A, child models: B,C  database table: A)

    3. TPC - When some models have hierarchy relationships, each child models will be mapped to independent database tables and all the database tables contain the property of the parent model. (eg. parent model: A, child models: B,C  database table: B,C)

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Shan Khan Monday, August 27, 2012 9:10 AM
    Monday, August 27, 2012 1:56 AM
    Moderator