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


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.

                ,Name = "GetAircraftByOperatorID")]
            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();
                        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.


    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



    • Proposed as answer by Fred Bao Tuesday, December 22, 2015 2:44 AM
    • Marked as answer by Fred Bao Monday, December 28, 2015 7:23 AM
    Sunday, December 13, 2015 9:46 AM