Page 1 of 1

Cannot remove an entity that has not been attached

Posted: Thu 30 Jun 2011 19:23
by maxgrante
Hi,
i'am a problem. I use DevArt DotConnect for MySQL 6.30 (latest release).

When i call:

Code: Select all

public void UpdateCarOptionals(List listCodGlo, Int64 idCar)
        {
            List listToDelete = this.GetCarOptionals(idCar).ToList();
            foreach (var item in listToDelete)
            {
                
                m_Model.AbCarsOptionals.DeleteOnSubmit(item);
            }
            
            foreach (String codGlo in listCodGlo)
            { 
                AbCarsOptional optToAdd = new AbCarsOptional();
                optToAdd.IdCar = idCar;
                optToAdd.CodGlo = codGlo;
                m_Model.AbCarsOptionals.InsertOnSubmit(optToAdd);
            }

                   m_Model.SubmitChanges();
        }
The first time all works fine, when i retry i get an exception of:

Code: Select all

Message: Cannot remove an entity that has not been attached.
Source: Devart.Data.Linq
StackTrace:    at Devart.Data.Linq.Table.b(Object A_0, MetaType A_1, Dictionary`2 A_2, Boolean A_3)
   at Devart.Data.Linq.Table.b(Object A_0, Boolean A_1)
   at Devart.Data.Linq.Table`1.DeleteAllOnSubmit[TSubEntity](IEnumerable`1 entities)
   at AutoCore.Models.CommonRepository.UpdateCarOptionals(List`1 listInc, Int64 idCar)
   at AutoCore.Models.CommonRepository.EditCarMainData(AbCar carToUpdate, Int32 codMar, Int32 codMod, Int32 codAll, Int16 idColor, Int32 mileage, Int16 regYear, Byte regMonth, Boolean metalyzed, Int16 purchaseYear, Byte purchaseMonth, Int16 genSat)
   at AutoWeb.Controllers.GarageController.CarEditMainDataSave(GarageEditMainDataViewModel gceMdVm)
The table have this schema:
CREATE TABLE `ab_cars_optionals` (
`Id` bigint(20) NOT NULL AUTO_INCREMENT,
`IdCar` bigint(20) NOT NULL COMMENT 'rif.auto',
`CodGlo` varchar(5) NOT NULL COMMENT 'codice optional normalizzato',
PRIMARY KEY (`Id`),
UNIQUE KEY `IdGarageCodGloUX` (`IdCar`,`CodGlo`),
KEY `FK_ab_cars_optionals_ice_normalized_registries` (`CodGlo`),
CONSTRAINT `FK_ab_cars_optionals_cars` FOREIGN KEY (`IdCar`) REFERENCES `ab_cars` (`Id`) ON UPDATE CASCADE,
CONSTRAINT `FK_ab_cars_optionals_ice_normalized_registries` FOREIGN KEY (`CodGlo`) REFERENCES `ice_normalized_registries` (`CodGlo`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=52 DEFAULT CHARSET=utf8

Can you help me?

Best regards.

Posted: Thu 30 Jun 2011 19:27
by maxgrante
If I restart IIS with iisreset the first execution work fine, from the second i crash with exception Cannot remove an entity that has not been attached

I have already test with a custom datacontext under using {} but don't work.

Posted: Thu 30 Jun 2011 19:30
by maxgrante
With driver version 6.30.165.0 (trial version) all work fine
With driver version 6.30.172.0 (full) from the second time i get exception

Posted: Fri 01 Jul 2011 16:46
by StanislavK
I've sent you a test project in a letter, please check that it was not blocked by your mail filter. Please specify what should be changed in the sample to reproduce the problem, or, if possible, please send us your test project.

Posted: Sat 02 Jul 2011 12:42
by maxgrante
Hi Stanislav,
I've created a test project that reproduce my problem.

You can download it here:
http://www.massimo-caselli.com/meta/AutoTest.zip

I have used the same stack of my real application:
- ASP.NET MVC 3 Application
- Visual Studio 2010
- Framework 4

Into the main folder you can find a dump SQL with a simplified table structure of my real application (the connection string is into Web.Config).

If you run the webapp, the HomeController, action Index work fine the first time, from the second time crash with "Cannot remove an entity that has not been attached"

I waiting for a response.

Thank you and best regards.

Massimo

Posted: Sat 02 Jul 2011 12:45
by maxgrante
For your info, if I use DeleteAllOnSubmit(List) the problem is the same.

Posted: Mon 04 Jul 2011 13:08
by StanislavK
Thank you for your assistance, we have reproduced the problem. We will inform you as soon as it is fixed.

Posted: Mon 04 Jul 2011 13:35
by maxgrante
Thanks Stanislav.
I will expect you. ;)

Posted: Tue 12 Jul 2011 15:33
by StanislavK
We have fixed this issue. The fix is available in the new 2.50.27 build of LinqConnect. The new build can be downloaded from
http://www.devart.com/linqconnect/download.html
(the trial and free versions) or from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

For the information about other fixes and improvements available in LinqConnect 2.50.27, please refer to
http://www.devart.com/forums/viewtopic.php?t=21451

Posted: Sun 17 Jul 2011 14:34
by maxgrante
Hi Stanislav,
all work fine.

Thanks.