我!我在c#wpf应用程序中工作。我正在使用FileHelpers将数据导出到csv文件。我正在使用.net实体框架,所以这个框架已经有了我的sql server数据库的类。 对于导出数据,Filehelpers说:
SqlServerStorage storage = new SqlServerStorage(typeof(OrdersVerticalBar));
storage.ServerName = "NEON-64";
storage.DatabaseName = "Northwind";
// Comment this for Windows Auth
storage.UserName = "Marcos";
storage.UserPass = "private :)";
storage.FillRecordCallback = new FillRecordHandler(FillRecordOrder);
OrdersVerticalBar[] res = storage.ExtractRecords() as OrdersVerticalBar[];
“OrdersVerticalBar”是我的班级
[DelimitedRecord("|")]
public class OrdersVerticalBar
{
public int OrderID;
public string CustomerID;
public int EmployeeID;
public DateTime OrderDate;
public DateTime RequiredDate;
[FieldNullValue(typeof(DateTime), "2005-1-1")]
public DateTime ShippedDate;
public int ShipVia;
public decimal Freight;
}
这是获取数据的方法:
protected void FillRecordOrder(object rec, object[] fields)
{
OrdersVerticalBar record = (OrdersVerticalBar) rec;
record.OrderID = (int) fields[0];
record.CustomerID = (string) fields[1];
record.EmployeeID = (int) fields[2];
record.OrderDate = (DateTime) fields[3];
record.RequiredDate = (DateTime) fields[4];
if (fields[5] != DBNull.Value)
record.ShippedDate = (DateTime) fields[5];
else
record.ShippedDate = DateTime.MinValue;
record.ShipVia = (int) fields[6];
record.Freight = (decimal) fields[7];
}
它说我要创建这个类,但实体框架已经创建了它。 所以,当我尝试获取数据时,我得到“BadUsageException”:
字段:'_ relationships'的类型为:RelationshipManager即 不是系统类型,所以这个字段需要CustomConverter(请检查 更多信息的文档。)
我尝试转换字段“_relationship”类型的RelationShipManager或忽略它,但不起作用。 我该如何解决这个问题? 谢谢!
答案 0 :(得分:0)
您可以在Engine.Options下手动设置要忽略或删除的字段,请参阅http://www.filehelpers.net/example/Advanced/DynamicChangeOptions/