I am trying to use the GetAll
method of Dapper contrib. Even though I have set a Key
in my entity, I get an exception:
GetAll only supports an entity with a [Key] or an [ExplicitKey] property
My entity:
using Dapper.Contrib.Extensions;
public class Customer
{
[Key]
int Recid { get; set; }
public string Name { get; set; }
public Customer()
{
}
}
And my Dapper method:
public IEnumerable<Customer> GetAllCustomers()
{
using (connection)
{
connection.Open();
return connection.GetAll<Customer>();
}
}
What am I doing wrong?
After fiddling around, I got it. The Key
field need to be public:
using Dapper.Contrib.Extensions;
public class Customer
{
[Key]
public int Recid { get; set; }
public string Name { get; set; }
public Customer()
{
}
}