I have a project that asks me to make such a BIG search engine, but which is dynamic. I mean, I can have from 0 to 9 main “groups” that have something like the infinite possibility of “where” with “OR” or “AND”. The first thing we think is to use Dynamic Linq, which are a good alternative for building a dynamic query. All this using EF with homemade packaging.
Problem : I cannot access the "Collections". I mean, I can easily access the reference object (for example, Customer.State.StateName = "New-York" or Custoemr.State.StateName = "Quebec"), but I cannot find a way to access what something like: Customer.Orders.OrderID = 2 OR Customer.Orders.OrderID = 3 ". I can easily understand this because of my collection, but how can I do it?
Please help me!
** Sorry for my English!!
Update
I don’t know, I think I'm sorry because I'm French ...
My problem is that nothing is static. Its a candidate search engine for a recruiting company that puts candidates for the enterprise. On the page where the manager can search for a candidate, he can "understand" by: Domain (Jobs), City (cities) or many others that the user filled in when he registered. All this in the format (if it was in SQL):
[...] WHERE (domaine.domainID = 3 OR domaine.domainID = 5 OR domaine.domainID = 23) AND (cities.cityID = 4, cities.city = 32) [...]
Therefore, I cannot do this with the usual LINQ format, for example:
Candidat.Domaines.Where(domain => domain.DomainID == 3 || domain.DomainID == 5 || domain.DomainID == 23);
Even the operator in the apiary is dynamic ("AND" or "OR")! This is why we are trying to use Dynamic Linq because it is much more flexible.
Hope its easier to understand my problem ...
Update 2
Here is my method
private string BuildDomainsWhereClause() {
StringBuilder theWhere = new StringBuilder();
if (this.Domaines.NumberOfIDs > 0) {
theWhere.Append("( ");
theWhere.Append(string.Format("Domaines.Where( "));
foreach (int i in this.Domaines.ListOfIDs) {
if (this.Domaines.ListOfIDs.IndexOf(i) > 0) {
theWhere.Append(string.Format(" {0} ", this.DispoJours.AndOr == AndOrEnum.And ? "&&" : "||"));
}
theWhere.Append(string.Format("DomaineId == {0}", i));
}
theWhere.Append(" ))");
}
return theWhere.ToString();
}
, "Boolean". , ?
: " " Boolean "".
- : "(Domaines.Where(DomaineId == 2 && DomaineId == 3 && DomaineId == 4 && DomaineId == 5))." LINQ:
var queryWithWhere = from c in m_context.Candidats.Where(WHERE)
select c;
, 7 8 "" ... ?