- Daryl Foster
- SnapObjects
- Thursday, 28 May 2020 08:02 AM UTC
Hi,
I'm having an issue with SqlModelMapper when I'm trying to Load with a modified SqlQueryBuilder. If I call SqlExecutor.Select with the SqlQueryBuilder it works ok, but if I call SqlModelMapper.Load with the same SqlQueryBuilder, it seems to ignore it and just use it's original query.
I want to use SqlModelMapper to take advantage of the nested model feature, otherwise I would just use SqlExecutor.
Originally I noticed the issue with some complex sql and model, but I can reproduce it with a simple model and sql. My function is below (I just uncomment the relevant return line to test both cases). Can anyone see any issues with my code?
public IList<codeDetails> Retrieve()
{
ISqlQueryBuilder queryBuilder =
ModelSqlBuilder.GetBuilder<codeDetails>(_dataContext).QueryBuilder;
queryBuilder.AsWhere().AndWhereRaw("code_details.table_id = 'PN'");
string sql = queryBuilder.ToSqlString(_dataContext);
Console.WriteLine(sql);
// This line works as expected
//return _dataContext.SqlExecutor.Select<codeDetails>(queryBuilder).ToList();
// This line ignores the modified queryBuilder
return _dataContext.SqlModelMapper.Load<codeDetails>(queryBuilder).ToList();
}
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.