Entity Framework and Splitting Confusion

Last post 05-20-2009 9:53 AM by cgeers. 1 replies.

Sort Posts:

  • Entity Framework and Splitting Confusion

    04-24-2009, 5:14 AM
    • Member
      54 point Member
    • jumpingmattflash
    • Member since 08-22-2006, 9:56 AM
    • Middlesbrough, GB
    • Posts 41
    Hi guys, I think i'm missing the point somewhere along the line when it comes to entity framework but i'm convinced I should be able to to do this. I've got two related tables, for the sake of argument lets call them person(personid, surname) and persontype(persontypeid, name). Person must have a persontype and a persontype can be assigned to zero or more person records. So I create the data model from my database and it sows up the correct linkage. I copy the persontype.name property into person and setup the mapping details so that person maps to persontype and the name property originates from persontype.name. Seems simple enough.. It won't compile now though, even if I remove the persontype entity from my page. The error I get is "Error 3024: Problem in mapping fragment.. Must specify mapping for all key properties (Person.PersonID, Person.PersonTypeID) of the EntitySet Person I'm at a loss as to where to go now, if I cant solve this issue i'm struggling to see the benefit in using Entity Framework over LINQ to SQL. Thanks, Matt
    -----------
    Matt Brooke
    Software & System Developer
    http://www.rocketscience.uk.com
    http://www.i-snapshot.com
  • Re: Entity Framework and Splitting Confusion

    05-20-2009, 9:53 AM
    • Contributor
      2,074 point Contributor
    • cgeers
    • Member since 02-21-2009, 2:41 AM
    • Belgium
    • Posts 275

    Jumpingmattflash,

    Setup your database structure as follows:

    Table [Person]

    • PersonId (Primary key)
    • Name
    • PersonTypeId

    Table [PersonType]

    • PersonTypeId (Primary key)
    • Name

    Put a foreign key on the [Person] table pointing to the [PersonType] table (Person.PersonTypeId -> PersonType.PersonTypeId). You should link a person to a type using the primary key value of the PersonType table, not the value of the name of the type.

    Next add a new Entity Data Model to your solution and have it generate a model from this database. Just select those two tables to include in the model.

    If you are having trouble with this, please send me a private message and I'll whip up an example.

    Regards,

    Christophe

     

    Please mark my reply as an answer if it helps you.

    Check out my blog
Page 1 of 1 (2 items)