In order to do method chaining with _Or_ operator, it would be necessary to save current the __query_ state in object in _Or_ method.
#QueryObject.cs
```
#region
using System;
using System.Linq.Expressions;
using LinqKit;
using Repository.Pattern.Repositories;
#endregion
namespace Repository.Pattern.Ef6
{
public abstract class QueryObject<TEntity> : IQueryObject<TEntity>
{
private Expression<Func<TEntity, bool>> _query;
public virtual Expression<Func<TEntity, bool>> Query()
{
return _query;
}
public Expression<Func<TEntity, bool>> And(Expression<Func<TEntity, bool>> query)
{
return _query = _query == null ? query : _query.And(query.Expand());
}
public Expression<Func<TEntity, bool>> Or(Expression<Func<TEntity, bool>> query)
{
return _query = _query == null ? query : _query.Or(query.Expand());
}
public Expression<Func<TEntity, bool>> And(IQueryObject<TEntity> queryObject)
{
return And(queryObject.Query());
}
public Expression<Func<TEntity, bool>> Or(IQueryObject<TEntity> queryObject)
{
return Or(queryObject.Query());
}
}
}
```
Add Method is not necessary any more; Use And or Or, instead. For example:
```
void Main()
{
var query = new BookQuery()
.OrElseTitleContains("Civitas")
.OrElseEditorContains("Civitas");
var q = new UnitOfWork(this).Repository<Book>().Query(query).Select();
q.Dump();
}
public class BookQuery: QueryObject<Libro>
{
public BookQuery OrElseTitleContains(string text)
{
Or(book => book.title.Contains(text));
return this;
}
public BookQuery OrElseEditorContains(string text)
{
Or(libro => libro.Editor.editor.Contains(text));
return this;
}
}
```
#QueryObject.cs
```
#region
using System;
using System.Linq.Expressions;
using LinqKit;
using Repository.Pattern.Repositories;
#endregion
namespace Repository.Pattern.Ef6
{
public abstract class QueryObject<TEntity> : IQueryObject<TEntity>
{
private Expression<Func<TEntity, bool>> _query;
public virtual Expression<Func<TEntity, bool>> Query()
{
return _query;
}
public Expression<Func<TEntity, bool>> And(Expression<Func<TEntity, bool>> query)
{
return _query = _query == null ? query : _query.And(query.Expand());
}
public Expression<Func<TEntity, bool>> Or(Expression<Func<TEntity, bool>> query)
{
return _query = _query == null ? query : _query.Or(query.Expand());
}
public Expression<Func<TEntity, bool>> And(IQueryObject<TEntity> queryObject)
{
return And(queryObject.Query());
}
public Expression<Func<TEntity, bool>> Or(IQueryObject<TEntity> queryObject)
{
return Or(queryObject.Query());
}
}
}
```
Add Method is not necessary any more; Use And or Or, instead. For example:
```
void Main()
{
var query = new BookQuery()
.OrElseTitleContains("Civitas")
.OrElseEditorContains("Civitas");
var q = new UnitOfWork(this).Repository<Book>().Query(query).Select();
q.Dump();
}
public class BookQuery: QueryObject<Libro>
{
public BookQuery OrElseTitleContains(string text)
{
Or(book => book.title.Contains(text));
return this;
}
public BookQuery OrElseEditorContains(string text)
{
Or(libro => libro.Editor.editor.Contains(text));
return this;
}
}
```