In ASP.Net Core, I can get a list of all my entities, and find a specific one by name:
var entities = _context.Model.GetEntityTypes();
var entity = (from e in entities where e.Name == $"MyNamespace.Models.{entityname}" select e).FirstOrDefault();
Console.WriteLine(entity.Name); //example output: MyNamespace.Models.Car
So I can access the entity name (or Model name) as a string, and now need to make that a class type for use by CsvHelper, because it requires that:
var records = csvReader.GetRecords<SomeClass>().ToList(); //typical use - not my code.
I tried to convert my entity to a Type as explained in this answer, so I do:
Assembly assem = typeof(MyNamespace.Models.Car).Assembly;
Type myType = Type.GetType(entity.Name); //entity.Name example: MyNamespace.Models.Car
var records = csvReader.GetRecords<myType>().ToList();
Unfortunately, this results in:
error CS0118: 'myType' is a variable but is used like a type
I don't understand why I get that error, or how to proceed.