none
Is there a way to tell if EF is loading values from the database? RRS feed

  • Question

  • I just started a new job, and the logic is very complex; I setup a breakpoint on certain properties to determine when they are changing, but 99% of the time it is just from EF loading the values from the database. I would like to know when EF is not loading values from the db so I can set a breakpoint if it is changed any other time than during a load from the db.

    We are using a DBContext that inherits from IdentityDBContext;

    Is there any way to determine the object is loading and Finished loading?

    Thank you,

    Wednesday, December 9, 2015 8:54 PM

Answers

All replies

  • Howdy from Texas Data.Juggler.

    Hey, let me see if I can help.  It sounds like you are using INotifyProperty change and each time the records are loaded into your collection (Observable Collection?) that it is firing off the PropertyChangedEvent.  Is that correct?

    Wednesday, December 9, 2015 9:03 PM
  • Since I don't check this routinely... Here is how I retrieve data via EF without launching the INotifyPropertyChanged. 

    Here is the EF Command for the data.  Note it returns an Array of the object.

            [Authorize]
            [HttpGet]
            [Route("ops/{OperID}"
                ,Name = "GetAircraftByOperatorID")]
            [ResponseType(typeof(Aircraft[]))]
            public IHttpActionResult GetAircraftByOperator(int OperID)
            {
                ////var currUser = System.Web.HttpContext.Current.User;
                ApiObjVersion = VersionHelper.GetVersion(this.Request);
                if (ApiObjVersion == 0)
                {
                    List<Aircraft> listAircraft = repository.GetByOperatorID(OperatorID);
                    if (listAircraft.Count.Equals(0))
                        return NotFound();
                    else
                    {
                        Aircraft[] aircrafts = listAircraft.ToArray<Aircraft>();
                        return Ok(aircrafts);
                    }
                }
                return null;
            }

    When the app calling procedure receives the data (within the ViewModel) it iterates thru the object array and adds them to an ObservableCollection of the object.  That observable collection is the starting point of data for the app and INotifyPropertyChange only occurs from that point forward.

    That help?  I'll be glad to share more.

    Cheers

    Wednesday, December 9, 2015 9:15 PM
  • i suggest you turn off the Lazy Loading feature which turn on default

    for more details, check below article

     http://www.entityframeworktutorial.net/EntityFramework4.3/lazy-loading-with-dbcontext.aspx


    DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.

    Sunday, December 13, 2015 9:46 AM