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
Solved

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

Posted on 2010-09-23
6
2,072 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
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.

 

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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