?
Solved

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

Posted on 2010-09-23
6
Medium Priority
?
2,189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 29

Assisted Solution

by:Gautham Janardhan
Gautham Janardhan earned 800 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 1200 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 1200 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
Independent Software Vendors: 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!

 

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 800 total points
ID: 33767358
yep thats correct
0
 

Author Closing Comment

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

Featured Post

Google Certified Professional - Cloud Architect

This course (1 of 3) is designed to help students who are interested in Google Cloud Platform (GCP) to become familiar with the platform, navigate the console and learn its capabilities. It will also prepare students for the Google Cloud Architect certification exam.

Question has a verified solution.

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

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 …
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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