fixer-m / snowflake-db-net-client

Snowflake .NET Client
Apache License 2.0
51 stars 14 forks source link

Issue with mapping #10

Closed dboretti closed 3 years ago

dboretti commented 3 years ago

Hi, I'm using the latest version of the library (0.3.4) with a .net core console app, target framework .NET 5.0 (but I've seen mapping doesn't work also with 3.1) The connection to SnowFlake using the standard constructor works, also the "ExecuteScalarAsync" method works, what is causing problems is "QueryAsync"

var comp = await snowflakeClient.QueryAsync<Companies_Global>("SELECT COMPANY_GUID, NAME FROM COMPANIES_GLOBAL;");

public class Companies_Global
{
    string Company_Guid { get; set; }
    string Name { get; set; }
}

"comp" has 3 items (which is correct) but all of them have the properties "Company_Guid" and "Name" always null when I highlight the "comp" item when debugging I see this:

{Snowflake.Client.SnowflakeDataMapper.d__2}

I've tried also to use QueryRawResponseAsync in this way but had the same issue:

var companies = await snowflakeClient.QueryRawResponseAsync("SELECT company_guid,name FROM COMPANIES_GLOBAL;");
var cg = SnowflakeDataMapper.MapTo<Companies_Global>(companies.Columns, companies.Rows);

in this latest example companies.Columns and companies.Rows are filled correctly by the QueryRawResponseAsync method with all the columns and all the rows data returned by the query

fixer-m commented 3 years ago

@dboretti, Hi!

Deserialization (i.e. mapping) doesn't work with private properties. You need to make them public, like this:

public class Companies_Global
{
    public string Company_Guid { get; set; }
    public string Name { get; set; }
}
dboretti commented 3 years ago

Oh what an oversight from my side, sorry for that, now it works perfectly, thanks very much! Very nice project! I count to use it for a very basic REST API instead of the standard .net connector