Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2344
  • 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
newbiewebSr. Software EngineerAuthor 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
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks. That's a great feature!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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