Entity property - save as json string in database

2 months ago
hi,

Im developing plugin in nopCommerce 4.60 and have this entity

public class KmStoresSnapshot : BaseEntity
{
    public IEnumerable<StoreInfo>? Data { get; set; }
    public uint Version { get; set; }
    public DateTime CreatedOnUtc { get; set; } = DateTime.UtcNow;
}


I want to save the Data property to the database as a string, and when fetched to convert it to StoreInfo collection.

Where is the right place to put the mapping code for this?
10x.
2 months ago
roishabtai wrote:
I want to save the Data property to the database as a string...

Then the property of your Entity class can't be complex type:
       public IEnumerable<StoreInfo>? Data { get; set; }
It needs to be a string.
Your  IEnumerable<StoreInfo> would just be serialized/deserialized locally as needed.

Look at how ...Xml fields are handled in the core code.  E.g.
Order.CustomValuesXml