Using Lstrings in Custom Module

Posted by Community Admin on 04-Aug-2018 22:47

Using Lstrings in Custom Module

All Replies

Posted by Community Admin on 21-Jul-2011 00:00

Hello,

Is it possible to use Lstring properties for model objects in a custom module that is not content-based? We would like to leverage the localization mechanisms built-in for some simple data elements without all the overhead of the content-based items.

We have tried adding properties of type Lstring - being careful not to include them in the Fluent mappings - but no columns appear in the database tables that are created.

Thank you!

Regards,
John

Posted by Community Admin on 27-Jul-2011 00:00

Hello John,

You can use Lstrings in non content based module. Lstring can be used in all persistent classes who use open access fluent mapping from his data provider.

To use the Lstring properly can you confirm you have all needed for a proper Lstring registration. You can see an example in the products module available with Sitefinity SDK.
Register the Lstring in ProductsItem.cs

[DataMember]
        [MetadataMapping(true, false)]
        public virtual Lstring WhatIsInTheBox
        
            get
            
                if (this.whatIsInTheBox == null)
                
                    this.whatIsInTheBox = this.GetString("WhatIsInTheBox");
                
 
                return this.whatIsInTheBox;
            
 
            set
            
                this.whatIsInTheBox = value;
                this.SetString("WhatIsInTheBox", this.whatIsInTheBox);
            
        
add it  at the bottom of the document too
private decimal price;
        private int quantityInStock;
        [Transient]
        private Lstring whatIsInTheBox;
Add entry to ProductItemViewModel.cs
public string WhatIsInTheBox
        
            get return this.whatIsInThebox;
            set this.whatIsInThebox = value;
        
...
private string whatIsInThebox;


Best wishes,
Stanislav Velikov
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 27-Jul-2011 00:00

Hi Stanislav,

I did grab that exact code from products and just modified the property name (I called it "ValueText"). When I had my model class derive from Content, the generated db table contained a value_text_ column, as well as a corresponding value_text_XX for each supported language.

When I changed my model to NOT derive from Content, these columns were no longer generated on the table, and I was unable to update or retrieve data from my ValueText property.

Is there other code elsewhere in the Products project that supports the WhatsInTheBox field that I have to replicate? I know not to list the Lstring properties in the FluentMappings.

Also, is there a good source of documentation for OpenAccess that describes all of the decorators (attributes) and what they do? (i.e. [Transient], [DataMember], etc). The OpenAccess documentation I've seen is all geared toward using the OpenAccess designer UI - and all of the Sitefinity example modules are not compatible with using this UI.

Thanks again!

Regards,
John

Posted by Community Admin on 29-Jul-2011 00:00

Hi John,

Other place is in ProductsManager.cs in the Copy method, but Copy is used to get the values from the database back to the module`s backend.

Best wishes,
Stanislav Velikov
the Telerik team

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed