Inosqlprovider Provider = nosqlmanager.create ("cloudtable");
Imongocollection<formmongodbmodel> collection = provider. Getcollection<formmongodbmodel, imongocollection<formmongodbmodel>> (Ctid);
#region Query Condition Stitching
Switch (listquerymodel.querytype)
{
Case "equal"://Equals
if (Listquerymodel.fieldtype = = "Datetime")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.eq ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (Listquerymodel.value)));
}
else if (Listquerymodel.fieldtype = = "Number" | | listquerymodel.fieldtype = = "Money" | | listquerymodel.fieldtype = = "Formu La ")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.eq ("field." + Listquerymodel.field + ".") + Queryconditiontype, convert.todouble ((Listquerymodel.value)));
}
Else
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.eq ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
}
Break
Case "notequal"://Not equal to
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.ne ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
Break
Case ' like '://contains
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.regex ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
Break
Case "Orlike":
string[] orlike_values = listquerymodel.value.Split (' | ');
list<filterdefinition<formmongodbmodel>> orlikelist = new List<filterdefinition<formmongodbmodel >> ();
for (int i = 0; i < orlike_values. Length; i++)
{
Orlikelist.add (BUILDERS<FORMMONGODBMODEL>. Filter.regex ("field." + Listquerymodel.field + ".") + Queryconditiontype, orlike_values[i]);
}
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.or (orlikelist));
Break
Case "Andlike":
string[] andlike_values = listquerymodel.value.Split (' | ');
list<filterdefinition<formmongodbmodel>> andlike_value = new list<filterdefinition< Formmongodbmodel>> ();
for (int i = 0; i < andlike_values. Length; i++)
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.regex ("field." + Listquerymodel.field + ".") + Queryconditiontype, andlike_values[i]);
}
Break
Case "Notlike":
string[] notlike_values = listquerymodel.value.Split (' | ');
list<filterdefinition<formmongodbmodel>> notlikelist = new list<filterdefinition< Formmongodbmodel>> ();
for (int i = 0; i < notlike_values. Length; i++)
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.not (BUILDERS<FORMMONGODBMODEL>. Filter.regex ("field." + Listquerymodel.field + ".") + Queryconditiontype, notlike_values[i]));
}
Break
Case "NULL":
filterdefinition<formmongodbmodel> filter = new Bsondocument ("field." + Listquerymodel.field + "." + Queryconditiontype, bsonnull.value);
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.and (filter));
Break
Case "Notnull":
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.ne ("field." + Listquerymodel.field + ".") + Queryconditiontype, bsonnull.value));
Break
Case "or":
string[] or_values = listquerymodel.value.Split (' | ');
list<filterdefinition<formmongodbmodel>> orlist = new list<filterdefinition<formmongodbmodel> > ();
for (int i = 0; i < or_values. Length; i++)
{
Orlist.add (New Bsondocument ("field." + Listquerymodel.field + ".") + Queryconditiontype, or_values[i]);
}
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.or (orlist));
Break
Case "Greater":
if (Listquerymodel.fieldtype = = "Datetime")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.gt ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (Listquerymodel.value)));
}
Else
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.gt ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
}
Break
Case "Greaterequal":
if (Listquerymodel.fieldtype = = "Datetime")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.gte ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (Listquerymodel.value)));
}
Else
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.gte ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
}
Break
Case ' less ':
if (Listquerymodel.fieldtype = = "Datetime")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. filter.lt ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (Listquerymodel.value)));
}
Else
{
List. Add (BUILDERS<FORMMONGODBMODEL>. filter.lt ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
}
Break
Case "Lessequal":
if (Listquerymodel.fieldtype = = "Datetime")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.lte ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (Listquerymodel.value)));
}
Else
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.lte ("field." + Listquerymodel.field + ".") + Queryconditiontype, listquerymodel.value));
}
Break
Case "between":
string[] between_values = listquerymodel.value.Split (' | ');
String between_value1 = Between_values[0];
String between_value2 = Between_values[1];
if (Listquerymodel.fieldtype = = "Datetime")
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.gt ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (between_value1)));
List. Add (BUILDERS<FORMMONGODBMODEL>. filter.lt ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.todatetime (between_value2)));
}
Else
{
List. Add (BUILDERS<FORMMONGODBMODEL>. Filter.gt ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.ToInt32 (between_value1)));
List. Add (BUILDERS<FORMMONGODBMODEL>. filter.lt ("field." + Listquerymodel.field + ".") + Queryconditiontype, Convert.ToInt32 (between_value2)));
}
Break
Default
Break
}
#endregion
result = collection. Find (BUILDERS<FORMMONGODBMODEL>. Filter.and (list). Skip (Pageskip). Limit (pagesize). ToList ();
MongoDB C # driver query