I have a bass class like this:
public abstract class Document
{
[Dapper.Contrib.Extensions.Key]
public Int32 DoucmentID {get;set;}
public String Name {get;set;}
}
Then I have
public class Proposal : Document
{
public String ProposalStuff {get;set;}
}
Now I want to write some generic method to handle updates using Dapper.Contrib
//some class somewhere..
public bool Update<T> (T as item) where T : class
{
using (var sqlConnection = new SqlConnection(_connectionString))
{
sqlConnection.Open();
return sqlConnection.Update<T>(item);
}
}
Now I want to update the object:
public bool UpdateProposal(Repository.Proposal prop)
{
return orm.UpdateItem<Repository.Proposal>(prop);
}
Dapper.Contrib gives me this message:
{"Entity must have at least one [Key] or [ExplicitKey] property"}
I am not able to find an example using an abstract base class. I thought maybe the type for the UpdateProposal should be Document but I get the same message.
Thanks for the help. I am sure it is something simple.
EDIT: I have found half the answer. I started testing just using a single class (no abstract) and got the same error. After further research:
I found that using Key [Dapper.Contrib.Extensions.Key] can solve the issue. It seems though that Key from ystem.ComponentModel.DataAnnotations should also work?
If not that makes me a little sad as any service that wants to use the ORM would have to know about Dapper and I was hoping to avoid a mapper.
Going to try now and break up the class again though and see if at least it solves the immediate issue.
M.