Hi , supppose I have a database view that returns 3 fields : Id , name , description
I need my output to be a class like this:
class myresults {
id
InfoClass Info ;
}
with Infoclass like this :
class Infoclass {
string name
string description;
}
that is , name and description are pushed into another class.
How can I accomplish this … ? can I replace the “database data” to “into” logic ? … or … even better add myself into the existing pipeline …
so that the id property is mapped by the default implementation and I can write the custom implementation to map name and descrition properties …
thank you
Just map it using code. There’s no built-in configuration that would map it into a different shape, code is the superior way to transform data. For advanced mapping like this I’d use a custom extension method.
var q = AutoQuery.CreateQuery(request, Request.GetRequestParams());
var ret AutoQuery.Execute(request, q);
return ret;
Should I replace the implementtion of AutoQuery.Execute to a custom one ?
or map the class returned by AutoQuery.Execute to my custom one ?
And what I should I put in the operation defintion …
this
public class MyOPeration : QueryBase<Myinputdto,DefaultReturnDto>
or this
public class MyOPeration : QueryBase<Myinputdto,MyCustomtReturnDto>
seem promising
… however I cannot make a clear sense out of it , since the public signature of the exeute method is not the one that is shown below
start -------------
As the implementation is trivial we can show the implementation inline:
public QueryResponse Execute(
IDbConnection db, ISqlExpression query)
{
var q = (SqlExpression)query;
return new QueryResponse
{
Offset = q.Offset.GetValueOrDefault(0),
Total = (int)db.Count(q),
Results = db.LoadSelect<Into, From>(q),
};
}
Basically just returns the results in an QueryResponse Response DTO. We also see that each query makes 2 requests, 1 for retrieving the total count for the query and another for the actual results, either limited by the request’s Skip or Take or the configured AutoQueryFeature.MaxLimit .
public class AutoQueryService : Service
{
public IAutoQuery AutoQuery { get; set; }
//Override with custom impl
public object Any(QueryOverridedRockstars dto)
{
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams());
q.Take(1);
return AutoQuery.Execute(dto, q);
}
public object Any(QueryOverridedCustomRockstars dto)
{
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams());
q.Take(1);
return AutoQuery.Execute(dto, q);
}
public object Any(StreamMovies dto)
{
var q = AutoQuery.CreateQuery(dto, Request.GetRequestParams());
q.Take(2);
return AutoQuery.Execute(dto, q);
}
}
A custom AutoQuery impl will allow some customization but note AutoQuery Services should be returning the prescribed response type, e.g: QueryResponse<T>.
As far as I understand … the obtain what I need there should be a kind of event /delegate called by the infrastructure … providing the “partially construted dto” and the current record of the datareader … so that I could push my “custom mapping” in the “default” flow.
I could accept having all the mapping done “by me” … still having the dynanic query conposition available. Could that be done ? I think I only need to access the dbconnection , since the query object is already available