c# - Store list of pairs in one table EF -
i used following class:
public class point { [required] public double x { get; set; } [required] public double y { get; set; } }
and model containing:
public list<point> vertices { get; set; }
but ef tries create separate table based on message :
entitytype 'point' has no key defined. define key entitytype.
i'll have large number of points related model , think it's not optimal solution have separate table. is there way embed point array inside table or thinking wrong?
highly appreciate time. thanks.
the following should work - not sure if recommend approach (as think table point ok) having said did seem work me. use verticedatatext store point data in string, stored in db:
public class vertice { public int verticeid { get; set; } [notmapped] public point[] data { { string[] rawinternaldata = this.verticedatatext.split(';'); point[] dataresult = new point[rawinternaldata.length / 2]; int count = 0; rawinternaldata.tolist().foreach(p => { var pairarray = p.split(','); dataresult[count++] = new point { x = double.parse(pairarray[0]), y = double.parse(pairarray[1])}; }); return dataresult; } set { stringbuilder sb = new stringbuilder(); value.tolist().foreach(p => sb.appendformat("{0},{1};", p.x, p.y)); this.verticedatatext = sb.tostring(); } } public string verticedatatext { get; set; } }
Comments
Post a Comment