Closed EthemAcar-Dev closed 2 years ago
How are you building the query? If you are using SqlBuilder or a plain string, you are responsible for the column to property mapping.
var query = SQL.SELECT("TOP (1) *").FROM("MyTableName"); var execution = _db.Map<MyTableName>(query)?.First();
Isn't this the correct way?
Try this:
var execution = _db.Table<MyTableName>()
.First();
Try this:
var execution = _db.Table<MyTableName>() .First();
Gives the same result back as my previous code. Seems like Column name property is not working correctly? Which is bad for me because there are some columns that start with numbers on my database and C# does not accept numbers as property names.
[Column(Name = "ColumnName")]
Are you using the Table attribute on the entity class?
Are you using the Table attribute on the entity class?
[Table(Name = "MyTableName")]
public class MyTableName
{
[Column(Name = "nOffer")]
public int Offer { get; set; }
}
Yeah like this.
This code :
var query = SQL.SELECT("TOP (1) *").FROM("MyTableName");
var execution = _db.Map<MyTableName>(query)?.First();
and this one:
var execution = _db.Table<MyTableName>().First();
Returns a row but the Offer parameter is value 0. In the database nOffer value is 257.
I cannot reproduce the issue. If you call _db.Table<MyTableName>().GetDefiningQuery().ToString()
what do you get? That way we can find out if it's using the column name or not.
Aha my bad it all makes sense right now.
DbExtensions uses the given Column name value to build SQL like:
SELECT [nOffer] AS [Offer]
FROM [MyTableName]
So if i build a query using DbExtensions SQL object i should type it as follow:
SQL.Select("TOP 1 [nOffer] AS [Offer]");
Which returns the correct database value.
Thank you very much for the support.
public class MyTableName { [Column(Name = "nOffer")] public int Offer { get; set; } }
This is my entity model. When I Map my query using DBExtensions I get 100 results back but the values are all 0.
If i change the property to table name like:
[Column(Name = "nOffer")] public int nOffer { get; set; }
Then i get correct values.