Using Lstrings in Custom Module
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
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);
private
decimal
price;
private
int
quantityInStock;
[Transient]
private
Lstring whatIsInTheBox;
public
string
WhatIsInTheBox
get
return
this
.whatIsInThebox;
set
this
.whatIsInThebox = value;
...
private string whatIsInThebox;
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
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