Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2233
  • Last Modified:

What does OnContextCreated() do in constructors of an ObjectContext?

I am learning the Nerd Dinner MVC2 demo and see inside the NerdDinnerEntities

partial void OnContextCreated();

I am trying to understand this syntax and where the code exists.  And what it does.

Thanks,
newbieweb
0
newbieweb
Asked:
newbieweb
  • 2
  • 2
  • 2
4 Solutions
 
Gautham JanardhanCommented:
this is a partial method declaration. so that you can extend the method in your partial class if needed.The method is invoked once the context has been created.
0
 
Bob LearnedCommented:
If it isn't clear, that syntax is a partial method, which is a 4.0 construct.

Partial Classes and Methods (C# Programming Guide)
http://msdn.microsoft.com/en-us/library/wa80x488.aspx

"A partial method declaration consists of two parts: the definition, and the implementation. These may be in separate parts of a partial class, or in the same part. If there is no implementation declaration, then the compiler optimizes away both the defining declaration and all calls to the method."
0
 
Bob LearnedCommented:
That line is the definition, so if you can extend the NerdDinnerEntities with another partial class:

   public partial class NerdDinnerEntities

The other partial class could have the implementation of OnDataChanged, if you need it, since the definition is already defined.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
newbiewebAuthor Commented:
Oh.  It's a definition for a function that doesn't even exist yet.  But if it ever should, like if I create the body, it will be called in all the right places already?  Is that right?
0
 
Gautham JanardhanCommented:
yep thats correct
0
 
newbiewebAuthor Commented:
Thanks. That's a great feature!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now