More in this section

Forums / Developing with Sitefinity / Using Lstrings in Custom Module

Using Lstrings in Custom Module

4 posts, 0 answered
  1. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    21 Jul 2011
    Link to this post
    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
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    27 Jul 2011
    Link to this post
    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
  3. John
    John avatar
    61 posts
    Registered:
    08 Jun 2012
    27 Jul 2011
    Link to this post
    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
  4. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    29 Jul 2011
    Link to this post
    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
4 posts, 0 answered