This is a migrated thread and some comments may be shown as answers.

Error duplicate Key; already exists in the cache of the object scope

3 Answers 182 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Harm
Top achievements
Rank 1
Harm asked on 24 Feb 2014, 11:00 AM
hello together,

I'm testing telerik and have the following problem.
I want to insert all missing records from table "order" in table "orderXML".

Table order
BetrNr Char(6), (primary key)
BelegNr int, (primary key)
Lieferant int,
.....

Table order XML
BetrNr Char(6), (primary key)
BelegNr int, (primary key)
uebertrage int ,
erledigt int ,
.....

I can identify all the missing records and also insert:

          IQueryable<BESTELLKOPF> query = from b in dbContext.orders
                                            .Include(hms => hms.orderXML)
                                            join r in dbContext.orders
                                            on b.BelegNr equals r.BELEGNR into temp
                                            from t in temp.DefaultIfEmpty()
                                            where b.BetrNr == "100000" &&
                                                  b.Lieferant == 69 &&
                                                  (t.BETRNR == null ||
                                                    t.ISTERLEDIGT == 0)
                                            select b;
 
            // jetzt alle nicht enthaltenen Sätze in orderXML einfügen
            foreach (order bestellung in query)
            {
                if (bestellung.orderXML == null)
                {
                    orderXML hms = new HMS_BESTELLXML();
                    hms.BETRNR = bestellung.BetrNr;
                    hms.BELEGNR = bestellung.BelegNr;
                    hms.ISTERLEDIGT = 0;
                    hms.ISTUEBERTRAGEN = 0;
                    hms.BEMERKUNG = "";
                    brz.Add(hms);
                }
            }
            dbContext.SaveChanges();

this works fine.

But if another program deletes records from the table "orderXML" the following error occurs:
Error duplicate Key; already exists in the cache of the object scope

I have tried the following

dbContext.cache.releaseAll();

dbContext.cache.release(dbContext.orderXMLs);


set the property "cache Policy" of orderXML to "NoCache"



Kind regards
Harm




3 Answers, 1 is accepted

Sort by
0
Ralph Waldenmaier
Telerik team
answered on 24 Feb 2014, 02:45 PM

Hello Harm,

Thank you for your interest in Telerik DataAccess.

I think the problem in your case is the query and the respective joins. Can you please try to see if the following query fulfills your requirements?

IQueryable<BESTELLKOPF> query = from b in dbContext.orders                                            
                                where
                                b.orderXML == null &&
                                b.BetrNr == "100000" &&
                                b.Lieferant == 69                              
                                select b;

In this case we are generating an outerjoin to the orderXml table and all the orders where the orderXml reference is null are returned.



Can you try to see if you are still experience the duplicate object key problems?

Hope this helps.

Do come back in case you have any other question.



Regards,

Ralph Waldenmaier
Telerik
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.

0
Harm
Top achievements
Rank 1
answered on 24 Feb 2014, 03:26 PM
Hello Ralph,

the query works, but I get no records.
I want to get all records that are "istErledit == 0" or not exists in table orderXML.

Your query gives me first back all the missing records. After inserting the records the query is empty.

Kind Regards
Harm
0
Ralph Waldenmaier
Telerik team
answered on 26 Feb 2014, 08:32 AM

Hello Harm,

Have you tried to add the condition to the where clause of your query like this?

IQueryable<BESTELLKOPF> query = from b in dbContext.orders                                            
                                where
                                (b.orderXML == null || b.ISTERLEDIGT == 0 )&&
                                b.BetrNr == "100000" &&
                                b.Lieferant == 69                              
                                select b;


This should give you back all the ones that are not yet in the orderXML table and also the ones that fulfil the ISTERLEDIGT == 0  condition.



Hope this helps.

Feel free to ask in case you have any other question.



Regards,

Ralph Waldenmaier
Telerik
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.

Tags
General Discussions
Asked by
Harm
Top achievements
Rank 1
Answers by
Ralph Waldenmaier
Telerik team
Harm
Top achievements
Rank 1
Share this question
or