locked
EFCore in memory save RRS feed

  • Question

  • User-357141231 posted

    Hi Guys.

    Trying to how out how EF handles changes before being saved to DB.

    For instance, I am checking the hashes of files, if a hash matches, I point the object to the hash of another object. Or if there is no hash, I create a hash.

    I call add or update depending.

    I will loop through this and then save at the end.

    I've noticed that unless saved, the hashes that have been updated or pointed to another has are not recognized unless it's saved to DB. I thought EF might keep a map in memory before saved, but this doesn't seem to be the case.

    Any recommendation here?

    Here's a snippet

    // check database for another copy
                        var _checkHash = _appDbContext.ImageHash.Where(h => h.Hash == _hash.ToString()).FirstOrDefault();
                        if (_checkHash != null)
                        {
                            Console.WriteLine("A match was found!");
    
                            // update image with hash from image found
                            _dbImageMagikImage.Hash = _checkHash;
                            _appDbContext.Update(_dbImageMagikImage);
    
    

    This will be looped through depending how many there are.

    Saturday, May 2, 2020 2:13 AM

All replies

  • User303363814 posted

    Do you have an error or exception?  If so, what are the details and where dos it occur in the code?  What are you expecting and what do you get?

    If the problem is with an Identity field that is generated by the database then it will not be valid until the database generates it.  Is this what you are talking about?

    Sunday, May 3, 2020 3:14 AM