in database, i've got column contains comma seperated values, so:
foo.bars varchar(100): @;1,5
in code, dto contains list<string>, so:
public class foo { public list<string> bars {get; set;} }
i'd petapoco do conversion me.
i've read imapper
interface couldn't find example of how use it.
how can achieve desired result?
here's solution think:
public class listmapper : imapper { public void gettableinfo(type t, tableinfo ti) { } public bool mappropertytocolumn(propertyinfo pi, ref string columnname, ref bool resultcolumn) { return true; } public func<object, object> getfromdbconverter(propertyinfo pi, type sourcetype) { return src => { if (sourcetype == typeof (string) && pi.propertytype == typeof (list<string>) && src != null) { return ((string) src).split(';').tolist(); } return src; }; } public func<object, object> gettodbconverter(type sourcetype) { return null; } }
database.mapper = new listmapper(); // mapper static property
Comments
Post a Comment