views:

368

answers:

0

I am creating an object called "letter" which has multiple "recipients" added to it.

when savechages is called on the context i get this error. "Entities in 'EchoEntities.LetterRecipients' participate in the 'FK_LetterRecipient_Letter' relationship. 0 related 'Letter' were found. 1 'Letter' is expected."

Also when only adding 1 recipient it works with two recipients it fails.

Shortened code:

using(Entites context = new Entities())
{
    Letter letter = new Letter
    {
        ID = Guid.NewGuid(),
        details = ""
    }

    Recipient recip = new Recipient
    {
        ID = Guid.NewGuid,
        Name = "Joe",
        Address = "123 some rd",
        City = "city",
        State = "state",
        Zip = "11111"
    }

    letter.Recipients.Add(recip);


    recip = new Recipient
    {
        ID = Guid.NewGuid,
        Name = "Bill",
        Address = "123 some rd",
        City = "city",
        State = "state",
        Zip = "11111"
    }

    letter.Recipients.Add(recip);

    context.AddToLetters(letter);
    context.SaveChanges();
}