My model looks something like this:
public class Product
{
public string Name {get; set;}
public string Description {get; set;}
public double Price {get; set;}
public List<string> Features {get; set;}
}
I want my database table to be flat - the List should be stored as a delimited string: Feature one|Feature two|Feature three for example.
When retrieved from the db, it should place each of those items back into a List
Is this possible?
I'm doing the very same in my current project, only I'm persisting a collection of enums as pipe-delimited numbers. It works the same way.
public class Product
{
protected string _features; //this is where we'll store the pipe-delimited string
public List<string> Features {
get
{
if(string.IsNullOrEmpty(_features)
return new List<String>();
return _features.Split(new[]{"|"}, StringSplitOptions.None).ToList();
}
set
{
_features = string.Join("|",value);
}
}
}
public class ProductMapping : ClassMap<Product>
{
protected ProductMapping()
{
Map(x => x.Features).CustomType(typeof(string)).Access.CamelCaseField(Prefix.Underscore);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With