简体   繁体   English

在 EF Effort 中加载 CSV 时,将不可为空的字段默认为默认类型值

[英]Defaulting non-nullable fields to default type value when loading CSVs in EF Effort

I'm using a CSV loader to load mock data into Effort.我正在使用 CSV 加载器将模拟数据加载到 Effort 中。 A colleague has checked in a change to one of our database tables (a new non-nullable column) and his gated-check-in failed because Effort was trying to assign a null value when we were expecting the values to be 0.一位同事签入了对我们的一个数据库表(一个新的不可为空的列)的更改,并且他的门控签入失败,因为当我们期望值为 0 时,Effort 试图分配一个空值。

Short of going back and changing every row in the CSV file, is there a way for us to have Effort populate these non-nullable columns default to the default value for their types?除了返回并更改 CSV 文件中的每一行之外,有没有办法让 Effort 填充这些不可为空的列默认为其类型的默认值?

Exception message:Effort.Exceptions.EffortException : An unhandled exception occurred while trying to assign value '[null]' to Property 'TaskQueueId' of type 'System.Int32' during entity initialization for table 

As in this example on https://entityframework-effort.net/load-data-from-csv :正如https://entityframework-effort.net/load-data-from-csv上的这个例子:

IDataLoader loader = new Effort.DataLoaders.CsvDataLoader(@"D:\CsvFiles")

using (NorthwindEntities ctx = Effort.ObjectContextFactory.CreateTransient(loader))
{
    var products = ctx.Products.ToList();
}

You can setup column value when objects are materialsed.您可以在对象材质化时设置列值。 Like if we have to set some property on Product objects:就像我们必须在Product对象上设置一些属性一样:

var products = ctx.Products.ToList();
foreach(var p in products)
{
    p.UnitPrice *=1.2m;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM