Dapper.Contrib icon indicating copy to clipboard operation
Dapper.Contrib copied to clipboard

SQL logic error near ")": syntax error - with Contrib

Open mshami85 opened this issue 7 years ago • 2 comments

Hi I've noticed that when making superclass as DAL containing CRUD operation with SQLite it always give this error the code is like that

public abstract class DataEntity : IDisposable
{ 
        public virtual void Insert()
        {
                using (var db = ConFactory.Connection)
                {
                    db.Open();
                    var tr = db.BeginTransaction();
                    db.Insert(this, tr);
                    tr.Commit();
                }
        }
}

and my classes looks like that

[Table("[test]")]
   public class Test : DataEntity
   {
       [Key]
       public int TestId { get; set; }

       public string Name { get; set; }
   }

using the code like this will result SQL logic error near ")": syntax error

using (Test t = new Test { Name = textBox2.Text })
{
     t.Insert();
     textBox1.Text = t.TestId.ToString();
 }

BUT when Insert method dragged to [Test] class it works perfectly

mshami85 avatar Mar 16 '18 23:03 mshami85

@mshami85 I'm getting this error suddenly. The insert was working fine at some point, but something I've changed has broken it. The problem I see is that we cannot see what SQL was executed. Why doesn't exception expose the insert statement so we've got any idea of what went wrong?

MelbourneDeveloper avatar Mar 08 '20 00:03 MelbourneDeveloper

I'm seeing this same issue as well... Super simple code var num = conn.Insert(item);

When I debug through decompiled source it is detecting a value for T of "object" and returning a table name of Objects as where to store the item. When I'm debugging I clearly see the type of the object as, in my case, BadActor.

Environment

  • Win10
  • VS 2022
  • dotnetcore 6
  • Dapper 2.0.123
  • Dapper.Contrib 2.0.78
  • Microsoft.Data.Sqlite 6.01
  • SQLitePCLRaw.bundle_winsqlite3 2.08
  • System.Linq.Async 6.01
  • System.Linq.Queryable 6.01

wobbet avatar Feb 11 '22 17:02 wobbet