我尝试从每天收到的CSV文件中读取数据时抛出此异常。我已经确认该列实际上确实存在于文件中。
文件中列的名称为sp_ac_input_voltage-unit(请注意破折号),我试图将其映射到名为sp_ac_input_voltage_unit的属性。该错误使我相信它正在寻找上面没有破折号的列,在这种情况下将找不到任何内容。
班级地图
public sealed class ClassMap : ClassMap<SimpleProduct>
{
public ClassMap()
{
AutoMap();
Map(m => m.web_short_description).Name("web_short_description-gno");
Map(m => m.web_long_description).Name("web_long_description-gno");
Map(m => m.web_page_key_words).Name("web_page_key_words-gno");
Map(m => m.web_page_description).Name("web_page_description-gno");
Map(m => m.manual_link).Name("manual_link-gno");
Map(m => m.web_page_title).Name("web_page_title-gno");
Map(m => m.additional_ph).Name("additional_ph-USD");
Map(m => m.manual_label).Name("manual_label-gno");
Map(m => m.video_links).Name("video_links-gno");
//Map(m => m.productSpecs);
References<ProductSpecsMap>(m => m.productSpecs);
}
}
public sealed class ProductSpecsMap : ClassMap<ProductSpecs>
{
public ProductSpecsMap()
{
Map(m => m.sp_ac_input_voltage).Name("sp_ac_input_voltage");
Map(m => m.sp_ac_input_voltage_unit).Name("sp_ac_input_voltage-unit");
}
}
分类地图注册
using (CsvReader reader = new CsvReader(new StreamReader(psm.message), new Configuration() { HasHeaderRecord = true, Delimiter = ";" }))
{
switch (psm.disposition)
{
case "GNO":
outputFile = Path.Combine(props.archiveDir, props.outputFile + props.suffix);
catalogId = "master-catalog";
reader.Configuration.RegisterClassMap<ClassMap>();
break;
代码失败
while (reader.Read())
{
index++;
var r = reader.GetRecord<SimpleProduct>(); <-- Failing on this line
编辑-添加简单产品/产品规格类,以帮助查找解决方案
public class SimpleProduct
{
other properties that are working fine
public ProductSpecs productSpecs { get; set; }
}
public class ProductSpecs
{
public string sp_ac_input_voltage { get; set; }
public string sp_ac_input_voltage_unit { get; set; }
}