Io uso dapper in .NET 4.5 per facilitare l'interrogazione del mio database MS SQl. I seguenti funziona bene:Dapper e "Operazione potrebbero destabilizzare il runtime" quando si nomina la colonna "Id"
NO PROBLEMI:
const string sql = @"
SELECT g.Name, g.Slug, g.CreatedDate, COUNT(r.Id) recipientCount
FROM Groups g
LEFT JOIN GroupRecipients r ON r.GroupId = g.Id
WHERE g.CustomerId = @CustomerId
GROUP BY g.Id, g.Name, g.Slug, g.CreatedDate
";
ritorno _connection.Query (SQL, new {CustomerId = customerId})(); ToList.
PROBLEMA SELEZIONE 'Id' COLONNA - AUMENTA VerificationException:
const string sql = @"
SELECT g.Id, g.Name, g.Slug, g.CreatedDate, COUNT(r.Id) recipientCount
FROM Groups g
LEFT JOIN GroupRecipients r ON r.GroupId = g.Id
WHERE g.CustomerId = @CustomerId
GROUP BY g.Id, g.Name, g.Slug, g.CreatedDate
";
return _connection.Query<GroupWithRecipientCount>(sql, new { CustomerId = customerId }).ToList();
L'eccezione viene generata con il messaggio 'operazione potrebbe destabilizzare il runtime.'
Qualcuno può individuare quello che potrebbe essere sbagliato qui? Il mio GroupWithRecipientCount classe assomiglia a questo:
public class GroupWithRecipientCount
{
public int Id { get; set; }
public DateTime CreatedDate { get; set; }
public string Name { get; private set; }
public string Slug { get; private set; }
public int RecipientCount { get; private set; }
}
EDIT 1:
ho rimosso questo:
Se Rinominare la colonna Id a qualcosa di diverso 'Id', tutto funziona bene, ovvero
"SELECT g.Id SomeOtherName, g.Name, ..."
Sembra che si interrompa anche se rinomina il campo ID della mia classe su SomeOtherName, quindi suppongo che il problema sia legato alla mappatura del campo Id, ma è solo un'ipotesi.
Questo errore suggerisce * Ho * fatto qualcosa di sbagliato, non tu ... dando una rapida occhiata, ma potrei non essere in grado di guardare correttamente proprio in questo momento –
Qual è il tipo esatto di 'g.Id' nel database ? –
Uniqueidentifier, Not Nothingble. –