locked
Entity Framework 4.0 - I disposed the object context, but i assigned the results to a public List<t>. Is there any performance issues about this? RRS feed

  • Question

  • Code here:

    interface IRepairOrder
        {
            List<RepairOrderHeader> GetAllRepairOrder();
        }
    
        public class RepairOrder:IRepairOrder
        {
            public List<RepairOrderHeader> ROdetLst = new List<RepairOrderHeader>();
    
            public List<RepairOrderHeader> GetAllRepairOrder()
            {
                using(var contex  = new DMISEntities())
                {
                    
                    var q = from item in contex.RepairOrderHeaders.Include("RepairOrderDetails")
                            select item;
                    ROdetLst = q.ToList();
                    return ROdetLst;
                }
            }
        }

    Wednesday, July 25, 2012 12:47 PM

Answers

  • On 7/25/2012 9:42 PM, Kenneth Cañet wrote:
    > Thank you for your feedback.
    >
    > As what sir @darnold924 says, we both send back a List<T> of
    > disconnected objects, my question is, if i do this all the time is there
    > any issues that will affect my application?
    >
    > Thank you again in advance..
    >
     
    They are objects, which are the heart of OOPs programming . The only
    issue you will have is how to mark an disconnected object dirty, connect
    it back in context for update or delete operations. It's not that big of
    a deal.
     
     
    Thursday, July 26, 2012 4:26 AM
  • Hi,

    "i do this" that is ? Do you mean calling GetAllRepairOrder or returning a List<T> from a method ?

    Each time GetAllRepairOrder is called, it will query the db each time and will load all data from these tables. It could possible that you call this method too often ?

    As a said previously starting from what you see could be easier as it depends how you use this method (caching the list would be good, calling GetAllRepairOrder each time you need this list would be bad and loading all data without any filtering is most often bad as more likely the user doesn't need to deal with them all).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".




    Thursday, July 26, 2012 8:18 AM

All replies

  • Hi,

    This is unrelated. The problem is more likely that you just load all the data without any filtering (how many rows to you have in the headers and details tables, how much time does it take) ? Usually you try to load just what is needed by the user to do its current task.

    Else I suggest to first describe the issue you have rather than asking if some particular code could cause an issue you didn't really described yet...


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".


    Wednesday, July 25, 2012 3:11 PM
  •  
    You have disconnected objects in this situation, and EF can't go back to
    the database again on disconnected objects. You could have pulled 1,000
    objects and iterated over the objects in a loop in the collection. It
    could have caused EF to go back and read the objects from the database
    1,000 more times if the connection context was still active.
     
    I do what you do all the time, which is send back a List<T> of
    disconnected objects.
     
    Wednesday, July 25, 2012 3:29 PM
  • Thank you for your feedback.

    As what sir @darnold924 says, we both send back a List<T> of disconnected objects, my question is, if i do this all the time is there any issues that will affect my application?

    Thank you again in advance..

    Thursday, July 26, 2012 1:42 AM
  • On 7/25/2012 9:42 PM, Kenneth Cañet wrote:
    > Thank you for your feedback.
    >
    > As what sir @darnold924 says, we both send back a List<T> of
    > disconnected objects, my question is, if i do this all the time is there
    > any issues that will affect my application?
    >
    > Thank you again in advance..
    >
     
    They are objects, which are the heart of OOPs programming . The only
    issue you will have is how to mark an disconnected object dirty, connect
    it back in context for update or delete operations. It's not that big of
    a deal.
     
     
    Thursday, July 26, 2012 4:26 AM
  • Hi,

    "i do this" that is ? Do you mean calling GetAllRepairOrder or returning a List<T> from a method ?

    Each time GetAllRepairOrder is called, it will query the db each time and will load all data from these tables. It could possible that you call this method too often ?

    As a said previously starting from what you see could be easier as it depends how you use this method (caching the list would be good, calling GetAllRepairOrder each time you need this list would be bad and loading all data without any filtering is most often bad as more likely the user doesn't need to deal with them all).


    Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".




    Thursday, July 26, 2012 8:18 AM