Underlying Record in Part is null...

Topics: Customizing Orchard, Writing modules
Dec 13, 2011 at 6:18 PM
Edited Dec 13, 2011 at 11:29 PM

I want to preface this, my first question, with some background information. I used to be a good developer. Due to health reasons, and some serious pain medications, I can no longer write code professionaly. It takes me forever to do something simple, so please bear with me. My questions may have obvious answers, but my troubleshooting skills have long since diminished.


I have a Part that uses the following for the property setters and getters:

public string Name {
  get { return Record.Name; }
  set { Record.Name = value; }
}

I have a ViewModel that uses the above part. I always get a NullReferenceException upon setting properties due to Record being NULL.

This Part is persisted to the database, when creating a new object do I need to create an empty one with a call to the Repository first?

Basically, how do I avoid the exception?

Thanks!

 

Coordinator
Dec 13, 2011 at 6:42 PM

Where are you creating the view model from? Where does the part come from? It seems like you just newed it up, whereas you should have gotten it from the content manager.

Dec 13, 2011 at 6:46 PM

Does the part have a Driver? 

I had this issue once because my part didn't have a Driver. (I have no idea why)

Dec 13, 2011 at 8:26 PM

I bet you are both right! 

See, the obvious things escape me.  I should have known that I needed the ContentManager to create the item before I could use it.

Thank you both for pointing me in the right direction!