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();
}
In the example it uses .FirstOrDefault(), but I need to use .ToList() to return multiple records.
My main aim is to be able to
1. Dynamically modify the where clause of a model which has nested models
2. Retrieve a list of the model with nested models
That is why I'm trying to use the SqlModelMapper. (My sample code above is just a simple case without a nested model so I haven't used .IncludeAll() after the Load).
Is there another way to retrieve nested models?