I've been struggling with getting ExpressMapper to map from a DataReader to a object (basically, Sqlite Rows -> Objects) . I've had success with AutoMapper, but found some other issues that got me looking for another map tool.
In AutoMapper I used the following code, but in ExpressMapper all string properties are NULL and the long prop is always 0, this indicates that the mapping is failing. Tried to look some examples for ExpressMapper but did not found any. Can you help? Also, are there any other mappers besides AutoMapper (and possibly ExpressMapper) that can help me achieve this scenario?
Thanks!
public class ImportedFiles
{
public Int64 Id { get; set; }
public String FileName { get; set; }
public String Hash { get; set; }
public ImportedFiles()
{
}
}
private static void ReadImportedFiles()
{
var lst = ReadData<ImportedFiles>("SELECT * FROM ImportedFiles").ToList();
}
public static IEnumerable<T> ReadData<T>(string queryString)
{
using (var connection = new SQLiteConnection(ConnectionBuilder.ConnectionString))
{
connection.Open();
using (var cmd = connection.CreateCommand())
{
cmd.CommandText = queryString;
using (var reader = cmd.ExecuteReader())
if (reader.HasRows)
while (reader.Read())
yield return Mapper.Map<IDataRecord, T>(reader);
}
}
}
Aucun commentaire:
Enregistrer un commentaire