public class template : entity { public template() { templateitems = new list<templateitem>(); } public int id { get; set; } public string name { get; set; } public virtual icollection<templateitem> templateitems { get; set; } } public class templateitem : entity { public int id { get; set; } public int templateid { get; set; } public string name { get; set; } public virtual template template { get; set; } } public sealed class templatemap : csvclassmap<template> { public templatemap() { map(m => m.name).name("name"); //map(m => m.templateitems).convertusing(row => new list<string> { row("nodetype") }); // how map collection value csv column } }
i reading csv file , need map csv columns 2 different tables have 2 different models tables ie template , templateitem templateitem mapped template how map csv class ?
currently not possible. need manually handle collections. 1 way of doing use convertusing
, if want keep in mapping file.
here example:
void main() { using (var stream = new memorystream()) using (var writer = new streamwriter(stream)) using (var reader = new streamreader(stream)) using (var csv = new csvreader(reader)) { writer.writeline("1,a,b,c"); writer.writeline("2,d,e,f"); writer.flush(); stream.position = 0; csv.configuration.hasheaderrecord = false; csv.configuration.registerclassmap<testmap>(); csv.getrecords<test>().dump(); } } public class test { public int id { get; set; } public list<string> names { get; set; } } public class testmap : csvclassmap<test> { public testmap() { map(m => m.id); map(m => m.names).convertusing(row => { var list = new list<string>(); list.add(row.getfield( 1 )); list.add(row.getfield( 2 )); list.add(row.getfield( 3 )); return list; }); } }
Comments
Post a Comment