Here is the top of the POCO I am using to create an object to install into my database table called "LOCITEMS":
[Table ("LOCITEMS")]
public class LOCITEMS :ICloneable
{
[ExplicitKey]
public string LOCATIONID { get; set; }
public string SITE_ID { get; set; }
[ExplicitKey]
public string ASCITEMID { get; set; }
public string ITEMID { get; set; }
[ExplicitKey]
public string SKIDID { get; set; }
public decimal QTYTOTAL { get; set; }
...
And here is the code I am using to insert the record into that table:
private async Task<bool>InsertNewLocItem(LOCITEMS item, IDbConnection conn, IDbTransaction trans )
{
if(item != null)
{
try
{
var x = await conn.InsertAsync<LOCITEMS>(item,trans);
return true;
}
catch (Exception ex)
{
return false;
}
}
else
{
return false;
}
}
When I check the var x it is always 0 and no record is getting inserted into my table. This is part of a transaction, and the transaction is committing, but the record is not showing up. I Added the "ExplicitKey" on the composite key columns for the table per other suggestions, but I am still not getting an insert, nor am I getting any errors in the "catch" either. What am I doing wrong?
I ended up running a SQL Trace from SSMS and was able to intercept the sql statements. Digging into the statements I found that one of the POCO fields was a string instead of a DateTime and was causing problems. I changed the field type and re-ran it and it inserted. I don't know why it wasn't throwing an error on the mismatch.