I have Event Class that has references to 2 objects Location and Category.
I write my SQL query string, and it works fine but when I put the query in dapper ORM.VS told me I have an inner exception. I am still getting the exception even after I use splitOn param.
Note: we use RecordID as col's name key col for the following tables Event, EventLocation and EventCategory. Is that a problem?
System.ArgumentException occurred HResult=0x80070057 Message=When using the multi-mapping APIs ensure you set the splitOn param if you have keys other than Id
public IEnumerable<Event> SelectEventsForList()
{
// using (var db = new )
var queryStr = @"SELECT
e.RecordID
,e.Title
,e.Description [Description]
,e.Location [LocationDetails]
,e.RegistrationRequired AS [IsRegistrationRequired]
,e.StartDate AS [EventDate]
,e.StartDate
,e.EndDate
,e.MaximumRegistrants
,eloc.RecordID
,eloc.DisplayName
,eloc.DisplayColour
,ecat.RecordID
,eCat.DisplayName
,eCat.DisplayColour
FROM dbo.Event e INNER JOIN dbo.EventLocation eloc ON e.LocationId = eloc.RecordID
INNER JOIN dbo.EventCategory eCat ON e.CategoryID = ecat.RecordID
WHERE eCat.Deleted = 0";
return this.dbConnection.Query<Event, Location, Category, Event>(
queryStr, (e, l, c) => {
e.Location = l; e.Category = c; return e;
},splitOn: "eloc.RecordID,ecat.RecordID");
}