Hi,

We've got the following code:

        using (Session.Current.DisableSaveChanges())
        {
            MOSPadExport mosPadExport = ImporteerBaseLineEnMaakNieuwProject();
            WerkpakketEntity werkPakket = CreeerNieuwWerkpakketMetActiviteit();
            UitvoerderEntity uitvoerder = Query.All<UitvoerderEntity>().FirstOrDefault();
            Assert.IsNotNull(uitvoerder, "Uitvoerder is null");
            OfferteEntity offerte = new OfferteEntity
            {
                PrognoseOntvangst = DateTime.Now.AddDays(20),
                Werkpakket = werkPakket,
                Uitvoerder = uitvoerder
            };

            return werkPakket;
        }

In the past we had some problems when creating entities without the 'DisableSaveChanges()' because DO would write entities to the DB before they were properly filled. The DisableSaveChanges() prevents entities being written to the DB before the are intialized correctly.

Today a unit test failed stating that a certain entity was not in the a certain entity set. I debugged it and found a weird problem. In the code below the entity is added to the list but after the Add it is not in the list at all:

        public void ItemAdded(object sender, WerkRegelEntity werkRegel)
    {
        using (new UserId(Projecten.Model.Entities.UserId.EnumUserId.Machine))
        {
            PadStatusMomentEntity.PadStatusMomentType statusType = GetStatusType(werkRegel);

            PadWerkRegelStatusMomentEntity statusMomentAanvraag = new PadWerkRegelStatusMomentEntity
            {
                WerkRegel = werkRegel,
                StatusType = statusType,
                Datum = DateTime.Now
            };

            werkRegel.PadActiviteit.PadStatusMomentList.Add(statusMomentAanvraag);
        }
    }

Setting a breakpoint directly after the add to the PadStatusMomentList and looking in the list the debugger tells me that the 'enumeration yielded no results'.

Now when I comment the 'using (Session.Current.DisableSaveChanges())' line out in the first code snippet, after the add the item is in the list.

So I am assuming here there is a bug in the DisableSaveChanges() code somewhere.

Regards Paul

asked Aug 16 '13 at 03:06

Paul%20Sinnema's gravatar image

Paul Sinnema
261888896


One Answer:

Hello Paul,

I think this is expected behavior.

Enumerating EntitySet is actually is doing a query (unless DO strictly knows all entity set items). Since you've disabled automatic changes saving newly added entity set item is not stored in the database at the moment you query for it.

answered Aug 16 '13 at 03:15

Denis%20Krjuchkov's gravatar image

Denis Krjuchkov
179325

We don't query inside the DisableSaveChanges but after that and also after a SaveChanges()

(Aug 16 '13 at 03:16) Paul Sinnema Paul%20Sinnema's gravatar image

I think it's strange that an item added in a list is not in the list. I would expect it NOT to be in the DB which is correct. But don't you agree its weird its not in the list?

(Aug 16 '13 at 03:19) Paul Sinnema Paul%20Sinnema's gravatar image

OK, this is somewhat different issue and needs checking. Thank you for report.

(Aug 16 '13 at 03:33) Denis Krjuchkov Denis%20Krjuchkov's gravatar image
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

powered by OSQA