Generated models property type changes after updating to latest version Umbraco 7 - umbraco

I've got an Umbraco site in Visual Studio that uses the generated Umbraco.Web.PublishedContentModels.dll for its models.
I'm trying to update this site from 7.5.6 to the latest version of Umbraco 7 (7.15.5). Along with the updated Umbraco CMS Nuget package, I get the updated Umbraco.ModelsBuilder 3.0.10.
Everything seems OK, but when I try to regenerate the Umbraco.Web.PublishedContentModels.dll through the backend, the generated DLL has different property types for certain models.
Mostly it's properties that used to be strings, that are now IPublishedContent. For instance, I've got a Document Type "Meal" that has a Media field "Photo". Photo used to be a string, but it's now Umbraco.Core.Models.IPublishedContent.
I inherited this site recently, so I'm not really sure how the type of the Photo property was generated as string to begin with. Has there been a change between 7.5 and 7.15 in how models are generated? Or was some configuration broken?
I guess I can rewrite each place where these properties are used to unwrap the IPublishedContent and get the right property out, but it'd be a lot of work that I would rather avoid.

Umbraco team added value converters to all built-in data types in v7.6.
Value converters can be disabled in ~/config/umbracoSettings.config:
<!-- Enables value converters for all built in property editors so that they return strongly typed object, recommended for use with Models Builder -->
<EnablePropertyValueConverters>true</EnablePropertyValueConverters>
You can find more details here:
https://issues.umbraco.org/issue/U4-7318

Related

what does the model.generated.cs file do in Umbraco?

Exploring Umbraco 8 and playing around building a test site etc.
Building document types and content pages via the back office interface, and looking in the code itself I've noticed a files called models.generated.cs.
looking inside, it contains partial classes like public partial class AndyTestPage : PublishedContentModel { } and properties I've given it like
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Umbraco.ModelsBuilder", "8.5.5")]
[ImplementPropertyType("andyProperty1")]
public string AndyProperty1 => this.Value<string>("andyProperty1");
my question is, what exactly is the point of this file? what does is do and how are these properties and classes created in here via the backoffice cms.
second question is, how would I go about creating a document type, and properties from code? my noob assumption is to simply add the classes in the this file, but that doesnt seem right?
Thanks,
Andy
It belongs to modelbuilder.
It depends on how you build your umbraco solution. If you use visual studio you can use something called strongly type, it helps building templates with VS.
By default, modelsbuilder is set to "PureLive", which is for users who builds within the umbraco backoffice system.
You can set modelsbuilder to different options, depending on how you build.
You should not edit the file, it is created and maintained by the system.
https://umbraco.tv/videos/umbraco-v7/implementor/working-with-umbraco-data/working-with-models-builder/
https://our.umbraco.com/documentation/reference/templating/modelsbuilder/
elitenet.dk has answered the first question
With regards to your second question Umbraco is database/content first so unfortunately you cant write documenttypes etc. from code first... not that i know of.
I beleive this is because Umbraco was designed to be used by almost anyone with a little html/css knowledge. E.g. You can create templates and views from the cms without having to know anything about serverside development.
Just a little tip if youre starting with Umbraco and plan on using multiple environments take a look at Kevin Jumps Usync package, essentually the package allows for document types/properties etc. to be pushed from environment to environment.Usync

Resharper file path hints/verification for Strings that represent a file path

Resharper auto-completes/hints and verifies file paths when I am in a Razor template and type an image tag's src attribute. However, throughout my ASP.net application I have many methods that take a String that represents a path to a file. Is there any way that I can enable this same verification and auto-completion functionality for those strings?
I am using VS 2013, Resharper 8.1, along with ASP.net MVC, and Web Essentials.
What you're asking can be solved by applying ReSharper's Code Annotations to your helpers! I recently recorded a webinar with JetBrains called ReSharper Secrets, where I talk in depth about Annotations, and actually show how to do the very thing you're asking! (around 32 minutes in)
Basically, you need to apply the [PathReference] attribute on the string parameter of your helper methods that represents the path, and you're done! I wrote a blog post about how to do it, you can read it here.

Symfony2 standalone Form component v2.3 - setting up a form

This is the same question asked here: Symfony2 standalone form component - setting up a form. The answer to this question seems to fully address the issue.
Unfortunately back when this question was asked the version of the form component was 2.0.x, and several things have changed since, for example the form creation using the form factory is quite different now compare the old code vs the new one.
I looked around but didn't find any documentation or examples on how to do this with the latest versions.
any updated versions of a sample application using the form component outside of Symfony2?
I have a repository demonstrating the standalone usage of the Form component for Symfony 2.1+ with both Twig and PHP as templating engine (check the branches): https://github.com/bschussek/standalone-forms/blob/2.1%2Btwig/src/setup.php
The crucial part is that you shouldn't instantiate FormFactory objects manually anymore (to give us core developers more flexibility in changing its constructor), but use the Forms class instead:
$formFactory = Forms::createFormFactoryBuilder()
->addExtension(new CsrfExtension($csrfProvider))
->addExtension(new ValidatorExtension($validator))
->getFormFactory();
A nice side benefit is that your IDE will list you the setters of the form factory builder, showing you what you can configure and how.

Umbraco - working with document types

I've started working with Umbraco yesterday and my vision of working with it was as follows:
add document types
create a basic content tree
create templates
edit document types & templates adding what I need and replacing "lorem ipsum" with the content from Umbraco
The problem is that I added two properties to a Client document type. Then I got this while trying to edit content:
Object reference not set to an instance of an object.
This is hard to understand for me, because:
Umbraco is supposed to be friendly ('the friendliest...')
Database structure is organized in a way that this should not be the problem
Even using Fluent NHibernate Migrator adding a field to a database just creates another field without throwing any exceptions - and here?
So what's the idea here? Document types are once and for all and you can't edit them?
First of all it would be helpful to know which version of Umbraco you are using as there are minor differences in the versions 4.x and now with v5 it's a completely different game with a complete new codebase on ASP.NET MVC.
In some versions of v4 there had been a bug where you get the error message you posted when you have added two document types with the same alias or two properties with the same alias to one document type.
So that you cannot edit the content is not the intention of umbraco ;-)

Help migrating asp.net mvc 1 to mvc 2

I just joined a team thats developing a asp.net mvc 1 application.
I only have visual studio 2010 installed which comes with mvc 2.
I ran the conversion wizard and now the app doesnt seem to compile
The error I get is
"Cannot apply indexing with [] to an
expression of type
'System.Web.Mvc.IValueProvider"
i get this error 5 times in different places of the app.
The line is
ModelState.SetModelValue(inputTagName, new ValueProviderResult(ValueProvider[inputTagName].AttemptedValue, file.FileName, System.Globalization.CultureInfo.CurrentCulture));
To be honest I've no clue on what its doing but my peers (using Mvc 1) dont have trouble compiling.
Please help.
This is one of the (few) breaking changes between MVC 1 and MVC 2. The ValueProvider has been completely redone to support multiple value providers and no longer has an index property. The short answer is to change this to use GetValue( inputTagName ). The longer (and better) answer is to change the code to use models for your action method inputs and not pull the data out of the value provider directly in your code. Rather, you rely on model binding to access the value provider and set the properties on your model.
Change ValueProvider[inputTagName].AttemptedValue to ValueProvider.GetValue(inputTagName).AttemptedValue.
Note that your entire team should be developing against the same version of ASP.Net MVC; otherwise; you'll run into lots of trouble.

Resources