private string CreateMultiCaml <T>(Dictionary <string, object> conditions) { Type entityType = typeof(T); int conditionCount = 0; string conditionCaml = string.Empty; foreach (var condition in conditions) { conditionCount++; if (conditions.Count > 1 && conditionCount != conditions.Count) { conditionCaml = "<And>" + conditionCaml; } string singleConditionCaml; PropertyInfo fieldProperty = entityType.GetProperty(condition.Key); singleConditionCaml = EntityHelper.PropertyIsLookup(fieldProperty) ? CreateLookupCaml(condition.Key, (int)condition.Value) : CreateFieldEqCaml(fieldProperty, condition.Value); if (conditions.Count > 1 && conditionCount == conditions.Count) { for (int i = 1; i < conditionCount - 1; i++) { conditionCaml = conditionCaml + "</And>"; } } } return(conditionCaml); }
public List <T> SelectItemsByFieldValue <T>(string fieldname, object value) where T : new() { Type entityType = typeof(T); PropertyInfo fieldProperty = entityType.GetProperty(fieldname); if (EntityHelper.PropertyIsLookup(fieldProperty)) { return(SelectItems <T>(new CamlQuery { ViewXml = CreateLookupCaml(fieldname, (int)value) })); } return(SelectItems <T>(new CamlQuery { ViewXml = CreateFieldEqCaml(fieldProperty, value) })); }