If the BO is marked as having a key with [key], why does dapper through an error?
[Table("tblWebReadyToWorkQualifications")]
public class TeacherQualificationBO
{
[Key]
public int TeacherID { get; set; }
public string ReadyToWorkGuid { get; set; }
public int QualificationID { get; set; }
}
Call to dapper that throws the exception
public IEnumerable<TeacherQualificationBO> GetTeacherQualifications(int TeacherID)
{
using (var connection = GetOpenConnection())
{
return connection.Get<IEnumerable<TeacherQualificationBO>>(TeacherID);
}
}
The table tblWebReadyToWorkQualifications
has a primary key on TeacherID
.
Error: at Dapper.Contrib.Extensions.SqlMapperExtensions.Get[T](IDbConnection connection, Object id, IDbTransaction transaction, Nullable`1 commandTimeout) in d:\egna projekt\dapper-dot-net\Dapper.Contrib\SqlMapperExtensions.cs:line 128\r\n
The error message is probably trying to tell you that the generic type IEnumerable<TeacherQualificationBO>
does not have a [Key] attribute, which is true. Only the type TeacherQualificationBO
does.
change
return connection.Get<IEnumerable<TeacherQualificationBO>>(TeacherID);
to
return connection.Get<TeacherQualificationBO>(TeacherID);
You also need to change the return type of your function to TeacherQualificationBO
to reflect this. You state that TeacherID
is a primary key (thus unique), so TeacherID
will only ever correspond to a single record. Thus it makes sense not to return a collection.