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

103 Views Asked by At

I'm using a CSV loader to load mock data into 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.

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?

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 
1

There are 1 best solutions below

0
TheVillageIdiot On

As in this example on 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:

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