Solved

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

Posted on 2010-09-23
6
2,052 Views
Last Modified: 2012-05-10
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
Comment
Question by:newbieweb
  • 2
  • 2
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 200 total points
ID: 33752274
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 300 total points
ID: 33755390
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
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 300 total points
ID: 33755426
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:newbieweb
ID: 33766472
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
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 200 total points
ID: 33767358
yep thats correct
0
 

Author Closing Comment

by:newbieweb
ID: 33768752
Thanks. That's a great feature!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question