none
How to access DataContext from within partial methods? RRS feed

  • Question

  • Hello!

    On my SalesOrder record I have a "Client ID" field, which is the FK to a customer record in another database. Using extension properties, I've added a readonly "CustomerRecord" property to the SalesOrder. A client has already been picked any time a new SalesOrder is being created, so conceptually it should have valid CustomerRecord value from it's inception. So, my two part question:

    A) To make sure that my SalesOrder has the CustomerRecord value, should I create a custom constructor for my SalesOrder in the partial class that requires a ClientID value, or should I handle the OnClientIDChanged event with a partial method, or something complete different?

    B) If I were to do either of the first two options from question A, how in my partial class can I access the current DataContext?

    Thanks!
    Sunday, March 22, 2009 7:09 PM

All replies

  • I have a similar question.  Somehow, with lazy loading, entities must know their current DataContext.... but I am not sure how this specifically works.  In some cases, I would like to add custom properties in my partial class that load data via the entities associated datacontext. 
    Anyone have thoughts, advice, help, pointers to good documentation, etc.???  Thanks!
    Friday, June 5, 2009 6:04 PM
  • You can't get access to the data context from the domain/entity object it relates to.

    Why not have LINQ to SQL maintain your CustomerRecord object for you by creating an association between them?  

    [)amien
    Saturday, June 6, 2009 3:01 AM
    Moderator