retrieving a part and creation

Topics: Writing modules
May 16, 2013 at 1:30 AM
I added a new part to the User content type called UserPhotoPart. I am trying to retrieve the part for the current user, using the following:

var userPhotosPart = _orchardServices.WorkContext.CurrentUser.As<UserPhotosPart>();

I just want to confirm behaviour. Shouldn't Orchard create and return a new part in this usage (if one doesn't already exist)? Either my memory is failing me, or I have something messed up in the migration.
Developer
May 16, 2013 at 8:13 AM
If you have attached a part to a user, then you will always get that part back.

If you dont have it coming back a few things to check are, 1. Have you got a driver for that Part? 2. Do you have a Handler with a Repository set up if you have a backing record...

N
May 16, 2013 at 8:32 AM
Edited May 16, 2013 at 8:37 AM
Yes I do have the handler and driver and the repository, which is why I'm confused as to why its not doing what I expect. Its Orchard... when everything is right it works beautifully. Miss one small detail and there is hell to pay trying to find it. I'll keep digging. Thanks for confirming the behavior.