Answer the question
In order to leave comments, you need to log in
How to assemble a request from parts?
Good!
Is it possible to assemble a query to the database from parts that will be formed based on the checked checkboxes?
For example, if the "date" checkbox is checked, then we add a condition for the date.
Answer the question
In order to leave comments, you need to log in
It is possible, but it is a difficult and winding path with a bunch of scattered rakes.
Much more direct - collect in the form or bunch (flag not cocked or condition by date)
You create your own class, which generates a request by analogy with the Builder pattern.
And at each stage, you pass the previous generated IQueriable if necessary.
class QueryBuilder
{
private IQueryable m_IQueryable;
//Создаем запрос в конструкторе
public QueryBuilder()
{
m_IQueryable = (from i in table select i);
}
//Добавляем условия
public void AddDate(DateTime timestamp)
{
m_IQueryable = m_IQueryable.Where(x => x.Timestamp == timestamp);
}
//Возвращает сформированый запрос
public IQueryable GetQuery()
{
return m_IQueryable;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question