I have this custom repo and when I try execute a query, it returns an exception If I execute the query using sql string, it does not return an error, but when I use some extention then I have this exception.
Like this:
public override IEnumerable<TableContrato> All()
{
//var query = "select * from Contrato";
//var data = Conn.Query<TableContrato>(query);
var data = Conn.GetList<TableContrato>();
return data;
}
All my entities are created in c# using "Table" Prefix, like TableContrato
, and my table is called Contrato
This way, I've build a custom mapper, like this.
public class CustomMapper<TTableEntity> : PluralizedAutoClassMapper<TTableEntity> where TTableEntity : class
{
public override void Table(string tableName)
{
tableName = tableName.Replace("Table", string.Empty).Trim();
base.Table(tableName);
}
}
and this is my repo base
public abstract class ReadOnlyRepositoryBase<TEntity, TTable, TKey> : IReadOnlyRepository<TEntity, TKey>
where TEntity : class where TTable : class
{
protected IDbConnection Conn { get; set; }
protected DapperContext Context { get; private set; }
protected ReadOnlyRepositoryBase()
{
Context = new DapperContext();
Conn = Context.Connection;
InicializaMappings();
}
public void InicializaMappings()
{
global::DapperExtensions.DapperExtensions.DefaultMapper = typeof(CustomMapper<>);
}
}
and here is my exception.
I know I could do all with literal queries, but this way I cannot use Expression trees for filtering, neither generics.
What I'm doing wrong?
EDIT: 26/05/2015 - TableContrato
public class TableContrato
{
public Guid ContratoId { get; set; }
public Guid EmpresaId { get; set; }
public string ContratoNome { get; set; }
public string ContratoCodigo { get; set; }
public DateTime? DataDeCriacao { get; set; }
public Guid? UsuarioQueCriou { get; set; }
public TableEmpresaGrupo Empresa { get; set; }
public virtual ICollection<TableLocal> Locais { get; set; }
}
UPDATE - 31/05/2016 - Sql profiler
Here is an image of Sql Server Profile, of executed Sql. Aparently, the '*' character is missed.
I think is a configuration error, so here is the map class
public class TableContratoMap : ClassMapper<TableContrato>
{
public TableContratoMap()
{
// ReSharper disable once RedundantBaseQualifier
base.Table("Contrato");
}
}
One more doubt... I'm familiar with EF mapping, where I don't need to map every single column. Is it really neccessary in Dapper?