How can I retrieve data from my SQL-Model using the SqlSelect attribute??? For now i do this;
[SqlParameter(name: "first", dataType: typeof(int))]
[SqlParameter(name: "second", dataType: typeof(string))]
[SqlParameter(name: "third", dataType: typeof(DateTime))]
[FromTable("mytable", Schema = "DBA")]
[SqlSelect("mycustomselect", RawSelect = "someproperty, otherproperty")]
public class MyClass
{
[Key]
[SqlColumn("first")]
public int First { get; set; }
[Key]
[SqlColumn("second")]
public string Second { get; set; }
[Key]
[SqlColumn("third")]
public DateTime Third { get; set; }
...
[SqlColumn("someproperty")]
public int Someproperty { get; set; }
[SqlColumn("otherproperty")]
public int Otherproperty { get; set; }
}
in my service I want to load this custom sqlSelect;
public async Task<MyClass> RetrieveOneAsync(int first, string second, DateTime third, string sqlselect, CancellationToken cancellationToken)
{
Myclass myclass;
var builder = ModelSqlBuilder.GetBuilder<Myclass>(_dataContext)
.GetQueryBuilder(sqlselect);
myclass = await _dataContext.SqlExecutor
.SelectOneAsync<Myclass>(
builder,
new object[]
{
first,
second,
third
},
cancellationToken);
return myclass;
}
i also tried it with a ParamValue;
public async Task<MyClass> RetrieveOneAsync(int first, string second, DateTime third, string sqlselect, CancellationToken cancellationToken)
{
Myclass myclass;
ParamValue firstParam = ParamValue.Input<int>("first", first);
ParamValue secondParam = ParamValue.Input<string>("second", second);
ParamValue thirdParam = ParamValue.Input<DateTime>("third", third);
var builder = ModelSqlBuilder.GetBuilder<Myclass>(_dataContext)
.GetQueryBuilder(sqlselect);
myclass = await _dataContext.SqlExecutor
.SelectOneAsync<Myclass>(
builder,
new object[]
{
firstParam,
secondParam,
thirdParam
},
cancellationToken);
return myclass;
}
and my call;
var myclass = await RetrieveOneAsync(1, "test", DateTime.Now, "mycustomselect", default);
Everytime i didnt get the right row. I think there are some problems with my parameters. Maybe the DateTime value cause some problems.
I already read how to get the SQLSelect (this works): GetQueryBuilder SqlSelectAttribute
but i dont get the right row from the table. Maybe i have to use a different function. SelectOneAsync