Adding manual properties into ModelsBuilder generated classes
Hi all,
I'm using the ModelsBuilder for the first time and loving it! It's really fantastic.
One issue that I can't get my head round is how I can add properties into the generated classes without them being removed when I re-run the VS custom tool. My use case here is essentially a ViewModel - the generated classes are being populated with the data from umbraco, thats fine, but in certain scenario's I want to add properties into the generated classes before passing them to the view from the controller. i.e. I'll manipulate those manual properties in the controller.
This post seems to highlight a similar topic, but i dont think it's quite the same as my scenario (or i can't quite understand it).
So all I had to do was to create a new Partial Class with the same name and constructor as was previously generated by the custom tool - and voila, are you really telling me that's all there is to it - that is absolutely genius!!!!
Adding manual properties into ModelsBuilder generated classes
Hi all,
I'm using the ModelsBuilder for the first time and loving it! It's really fantastic.
One issue that I can't get my head round is how I can add properties into the generated classes without them being removed when I re-run the VS custom tool. My use case here is essentially a ViewModel - the generated classes are being populated with the data from umbraco, thats fine, but in certain scenario's I want to add properties into the generated classes before passing them to the view from the controller. i.e. I'll manipulate those manual properties in the controller.
This post seems to highlight a similar topic, but i dont think it's quite the same as my scenario (or i can't quite understand it).
Is what I'm asking possible?
Thanks for your time in advance higgsy
Hi Higgsy,
The generated classes are partial so that you can add your own partial classes in separate files so they don't get over written.
Check out the documentation here https://github.com/zpqrtbnk/Zbu.ModelsBuilder/wiki/Understand-And-Extend
Jeavon
p.s Extending section
So all I had to do was to create a new Partial Class with the same name and constructor as was previously generated by the custom tool - and voila, are you really telling me that's all there is to it - that is absolutely genius!!!!
Yes, exactly!
Absolutely genius - umbraco gets better every day. Thanks for your help - greatly appreciated.
is working on a reply...