none
An item with the same key has already been added exception - entity framework with VS2012 RRS feed

  • Question

  • I am currenly reading julie lerman's entity framework book (2nd edition) and implementing its examples on VS 2012.

    For those who know/read it, i am currently on chapter 9, using BreakAway database model.

    This is the link to download the DB from her site: (on chapter 8)

    http://learnentityframework.com/LearnEntityFramework/downloads/#2ed

    When i try to do just a small query like:

    var context = new BAGA.BAEntities();
    List<BAGA.Customer> customers=
    context
    .Customers.Include("Contact")
    .Include("PrimaryActivity")
    .Include("SecondaryActivity")
    .Include("PrimaryDestination")
    .Include("SecondaryDestination")
    .Include("Reservations.Trip.Destination")
    .ToList();
    customerBindingSource
    .DataSource = customers;

    I get the exception say's: An item with the same key has already been added.

    I read on some posts that there's might be a problem with primary or foreign keys in the scheme but couldn't find one issue on the database that can cause this.

    Can someone point the problem on that database's tables or the domain model it creates? I am using VS2012 for the examples on the book.

    Or, am i doing somthing wrong? (although, i haven't do anything yet :))

    Thanks


    • Edited by YanivHer Tuesday, October 2, 2012 10:18 AM
    Tuesday, October 2, 2012 10:04 AM

Answers

  • Hi YanivHer;

    The error seems strange for getting data I would expect this type of error if you were updating the database. If you can zip up your complete project and put in in a public folder on your SkyDrive I will download it and have a look.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Thursday, October 11, 2012 5:41 AM
    Tuesday, October 2, 2012 3:06 PM

All replies

  • Hi YanivHer;

    The error seems strange for getting data I would expect this type of error if you were updating the database. If you can zip up your complete project and put in in a public folder on your SkyDrive I will download it and have a look.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Thursday, October 11, 2012 5:41 AM
    Tuesday, October 2, 2012 3:06 PM
  • I have deleted the database and recreated it (it's just a double click on some installer from the book's download site) and then i have created the edmx file again.

    The exception was gone. (i had other ones but i managed those).

    Thank you for the reply

    Yaniv

    Wednesday, October 3, 2012 10:55 PM