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

Dapper Contrib does not support HANA?

Open jose-dvm opened this issue 5 years ago • 5 comments

Using Get method with HanaConnection and OdbConnection classes I get an error, it seems that the placeholder for the Id in the query (an @, I always have used ? for Hana) is not replaced.

Code:

HanaConnection connection = new HanaConnection("connectionString");

connection.Open();

var invoice = connection.Get<Invoice>(63829);

My Invoice class:

[Table("OINV")]
public class Invoice
{
    [ExplicitKey]
    public int DocEntry { get; set; }
    public string CardCode { get; set; }
    public string FakeProperty { get; set; }
 }

The error:

syntax-error-dapper

jose-dvm avatar Aug 27 '20 08:08 jose-dvm

I am not familiar with that DB. Can you show what you would have used with manual ADO-NET? It sounds like ?foo? etc should work (mapping to the value named foo in the args passed)

On Thu, 27 Aug 2020, 09:13 dvm-j, [email protected] wrote:

Using Get https://dapper-tutorial.net/get method with HanaConnection and OdbConnection classes I get an error, it seems that the placeholder for the Id in the query (an @, I always have used ? for Hana) is not replaced.

Code:

HanaConnection connection = new HanaConnection("connectionString"); connection.Open(); var invoice = connection.Get<Invoice>(63829);

My Invoice class:

[Table("OINV")]public class Invoice { [ExplicitKey] public int DocEntry { get; set; } public string CardCode { get; set; } public string FakeProperty { get; set; } }

The error:

[image: syntax-error-dapper] https://user-images.githubusercontent.com/47435846/91414962-98172180-e84d-11ea-86ec-119672738f8b.JPG

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/StackExchange/Dapper/issues/1526, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAEHMDXXE44H3IFKXVYBFTSCYIRHANCNFSM4QMWNI2Q .

mgravell avatar Aug 28 '20 06:08 mgravell

Sorry for the delay. Using ADO it looks like this, either with Hana or Odbc classes.


HanaConnection connection = new HanaConnection("connectionString");

connection.Open();

var command = new HanaCommand(@"SELECT ""DocEntry"", ""CardCode"" FROM OINV WHERE ""DocEntry"" = ?", connection);

command.Parameters.AddWithValue("DocEntry", 63829);

var reader = command.ExecuteReader();

while(reader.Read())
{
    var invoice = new Invoice();

    invoice.DocEntry = Convert.ToInt32(reader["DocEntry"]);
    invoice.CardCode = reader["CardCode"].ToString();

    Console.WriteLine("Invoice #{0}. Customer: {1}.", invoice.DocEntry, invoice.CardCode);
}

Using regular Dapper this also works:

string query = @"SELECT ""DocEntry"", ""CardCode"" FROM OINV WHERE ""DocEntry"" = ? ";

var invoice = connection.QueryFirstOrDefault<Invoice>(query, new { DocEntry = 63829 });

Console.WriteLine("Invoice #{0}. Customer: {1}.", invoice.DocEntry, invoice.CardCode);

jose-dvm avatar Sep 01 '20 10:09 jose-dvm

Can confirm this issue. I am not using Dapper.Contrib but the original Dapper and got the same error. Seems like query params having the "@"-notation are not replaced correctly. Using "?" works.

ancoroc avatar Aug 13 '21 13:08 ancoroc

The default parameter prefix for HANA is a colon ":" not an "@" if that's helpful.

rabbers avatar Apr 25 '22 09:04 rabbers

You must pass parameter between ?

Example SELECT * FROM "table" WHERE ""col"" = ?col?

zanyar3 avatar Dec 05 '22 07:12 zanyar3