none
Get Collection in which Current Entity Exist RRS feed

  • Question

  • Hello

    I have one DataClass1DataContext With Northwind Order Table ( Linq to sql used).

    In it Suppose in my window I write following code..

    DataClasses1DataContext dc = new DataClasses1DataContext();
    
    BindingList<Order> orderLst = dc.Orders.GetNewBindingList() as BindingList<Order>;
                
    Order order = orderLst.First();

    Now From "order"  variable ( entity)  I want to get the collection in which it exist that is "orderLst".


    Can you please suggest some way like some reflaction or some mechanism so thai I can get Collection in which Current entity exist.

    Can you please suggest any way to achieve this kind of mechanism?

    Thanking you in advance..

    Regards

    Vipul



    Tuesday, December 16, 2014 1:25 PM

Answers

  • You cannot.  Suppose that after the Order line you set the collection to Null or the collection goes out of scope.

    One thing you could do is create a reference in the Order object that holds the collection but then you have to realize that since it is a reference it can exist in more than one collection.

    All that to say that there is no "easy" method to do what you want.


    Lloyd Sheen

    Tuesday, December 16, 2014 3:03 PM

All replies

  • You cannot.  Suppose that after the Order line you set the collection to Null or the collection goes out of scope.

    One thing you could do is create a reference in the Order object that holds the collection but then you have to realize that since it is a reference it can exist in more than one collection.

    All that to say that there is no "easy" method to do what you want.


    Lloyd Sheen

    Tuesday, December 16, 2014 3:03 PM
  • You might sometimes get the DataContext but it could have been set to Null.  No objects in Dot.Net can get their "owner" unless they store a reference to that owner.

    Lloyd Sheen

    Wednesday, December 17, 2014 10:34 PM
  • Ok

    Can you please suggest me some way how to set reference & How it will be structured?

    Thursday, December 18, 2014 3:53 AM
  • Hello Langalia,

    Any update? I have marked sqlguy reply as answer since I think it is helpful, if you think it provides no help, please unmark it and for a new question, it is suggested to open a new thread.

    Thank you for your understanding and support.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, December 29, 2014 9:01 AM
    Moderator