public static IQueryable<TEntity> IncludeDependencies<TEntity>(
this IQueryable<TEntity> query,
IList<string> deps)
where TEntity : class
{
foreach (string dependency in deps)
{
query = query.Include(dependency);
}
return query;
}
class BaseFilter {
// public int Skip { get; set; }
// public int Take { get; set; }
// public string OrderBy { get; set; }
// ...
public IList<string> Dependencies { get; set; }
}
class ImageFilter: BaseFilter {
//...
public const string WITH_TAGS = $"{nameof(Image.ImageTags)}.{nameof(ImageTag.Tag}";
}
// somewhere in base repository
public virtual Task<IList<TEntity>> GetAsync<TFilter>(TFilter filter)
where TFilter: BaseFilter
{
IQueryable<TEntity> query = this.QueryableEntities;
if (filter?.Dependencies != null)
{
query = query.IncludeDependencies(filter.Dependencies);
}
//...filtration, ordering, pagination
return query.AsNoTracking().ToListAsync();
}
// Usage:
var filter = new ImageFilter {
Skip = (pageNo - 1) * ITEMS_PER_PAGE,
Take = ITEMS_PER_PAGE,
Dependencies = new [] { ImageFilter.WITH_TAGS },
};
var result = await imageRepository.GetAsync(filter);
Если нет смысла вести детальную документацию, то кто будет знать все о проекте?
cellValues[][]
хранятся значения таблицы. Тогда:auto treeWidget = new QTreeWidget();
for (int rc = 0; rc < maxRow; rc++) { // map each row
QStringList rowName( QString("Row#%1").arg(rc) );
auto rowNode = new QTreeWidgetItem(nullptr, rowName);
// map children for row (cells)
for (int cc = 0; cc < maxCol; cc++) {
QStringList cellName( cellValues[rc][cc] );
auto cellNode = new QTreeWidgetItem(rowNode, cellName);
}
treeWidget->addTopLevelItem(rowNode);
}
QTreeWidget *treeWidget = new QTreeWidget();
treeWidget->setColumnCount(1);
QList<QTreeWidgetItem *> items;
for (int i = 0; i < 10; ++i)
items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(QString("item: %1").arg(i))));
treeWidget->insertTopLevelItems(0, items);