Click here to Skip to main content
15,891,900 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Problem with TCP socket in Windows service Pin
mavrick233-Feb-10 23:18
mavrick233-Feb-10 23:18 
GeneralRe: Problem with TCP socket in Windows service Pin
SeMartens4-Feb-10 1:46
SeMartens4-Feb-10 1:46 
QuestionHow To Create Printer Driver Pin
Anubhava Dimri3-Feb-10 18:47
Anubhava Dimri3-Feb-10 18:47 
AnswerRe: How To Create Printer Driver Pin
Eddy Vluggen3-Feb-10 21:58
professionalEddy Vluggen3-Feb-10 21:58 
GeneralRe: How To Create Printer Driver Pin
Anubhava Dimri3-Feb-10 22:03
Anubhava Dimri3-Feb-10 22:03 
GeneralRe: How To Create Printer Driver Pin
Richard MacCutchan3-Feb-10 22:06
mveRichard MacCutchan3-Feb-10 22:06 
QuestionEnterprise Library Configuration tool Pin
Peter Trevor3-Feb-10 10:14
Peter Trevor3-Feb-10 10:14 
QuestionEntity data model with Master-detail scenario [modified] Pin
Ravi Mori3-Feb-10 3:26
Ravi Mori3-Feb-10 3:26 
hi,
I am using entity data model and i have master-detail scenario.(Patient-PatientAddresses)

Everything is going on fine if i am updating any data either in master table or detail table.

But when i am going to insert a new detail record while updating master entity, it gives me following error :
"An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key."

I googled so much, but not getting proper idea.

Here is my code :

using (var context = new Entities())
            {
                try
                {
                    var record = (from p in context.Patient.Include("PatientAddress")
                                  where p.PatientId == patient.PatientId
                                  select p).FirstOrDefault();
                    
                    if (record == null)
                    {
                        context.AddToPatient(patient);
                    }
                    else
                    {
                        foreach (var item in patient.PatientAddress)
                        {
                            if (item.EntityKey == null)
                            {
                                context.AddToPatientAddress(item); // <--Throws Exception here.
                                continue;
                            }
                            context.ApplyPropertyChanges("PatientAddress", item);
                        }
                        context.ApplyPropertyChanges("Patient", patient);
                    }
                    context.SaveChanges();
                    return true;
                }
                catch
                {
                    return false;
                }
            }




Any suggessions is appreciated.

modified on Wednesday, February 3, 2010 9:55 AM

AnswerRe: Entity data model with Master-detail scenario Pin
Dave Kreskowiak3-Feb-10 3:46
mveDave Kreskowiak3-Feb-10 3:46 
GeneralRe: Entity data model with Master-detail scenario Pin
Ravi Mori3-Feb-10 3:57
Ravi Mori3-Feb-10 3:57 
GeneralRe: Entity data model with Master-detail scenario Pin
Dave Kreskowiak3-Feb-10 6:13
mveDave Kreskowiak3-Feb-10 6:13 
AnswerRe: Entity data model with Master-detail scenario Pin
Not Active3-Feb-10 4:28
mentorNot Active3-Feb-10 4:28 
GeneralRe: Entity data model with Master-detail scenario Pin
Ravi Mori3-Feb-10 6:25
Ravi Mori3-Feb-10 6:25 
QuestionGenerate popup desktop application Pin
RA|-|UL PATEL3-Feb-10 2:34
RA|-|UL PATEL3-Feb-10 2:34 
AnswerRe: Generate popup desktop application Pin
Not Active3-Feb-10 2:56
mentorNot Active3-Feb-10 2:56 
AnswerRe: Generate popup desktop application Pin
Luc Pattyn3-Feb-10 3:00
sitebuilderLuc Pattyn3-Feb-10 3:00 
GeneralRe: Generate popup desktop application Pin
Pete O'Hanlon3-Feb-10 3:55
mvePete O'Hanlon3-Feb-10 3:55 
GeneralRe: Generate popup desktop application Pin
Luc Pattyn3-Feb-10 4:03
sitebuilderLuc Pattyn3-Feb-10 4:03 
GeneralRe: Generate popup desktop application Pin
RA|-|UL PATEL3-Feb-10 20:32
RA|-|UL PATEL3-Feb-10 20:32 
GeneralRe: Generate popup desktop application Pin
Dave Kreskowiak3-Feb-10 23:41
mveDave Kreskowiak3-Feb-10 23:41 
GeneralRe: Generate popup desktop application Pin
RA|-|UL PATEL4-Feb-10 2:45
RA|-|UL PATEL4-Feb-10 2:45 
GeneralRe: Generate popup desktop application Pin
Luc Pattyn4-Feb-10 0:02
sitebuilderLuc Pattyn4-Feb-10 0:02 
Generalbluetooth programming Pin
Jamal Abdul Nasir2-Feb-10 8:32
Jamal Abdul Nasir2-Feb-10 8:32 
GeneralRe: bluetooth programming Pin
Richard MacCutchan2-Feb-10 8:42
mveRichard MacCutchan2-Feb-10 8:42 
QuestionOverlay Text to fit on Any Image Pin
Member 39257262-Feb-10 4:32
Member 39257262-Feb-10 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.