/// <summary> /// Adds a retrieve multiple request to the current OrganizationRequestCollection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="requests">The requests.</param> /// <param name="columnSet">The column set.</param> /// <param name="columnNameAndValuePairs">The column name and value pairs.</param> public static void AddRetrieveMultiple <T>(this OrganizationRequestCollection requests, ColumnSet columnSet, params object[] columnNameAndValuePairs) where T : Entity { requests.Add(new RetrieveMultipleRequest { Query = QueryExpressionFactory.Create <T>(columnSet, columnNameAndValuePairs), }); }
/// <summary> /// Adds a retrieve multiple request to the current OrganizationRequestCollection. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="requests">The requests.</param> /// <param name="anonymousTypeInitializer">The anonymous type initializer.</param> /// <param name="columnNameAndValuePairs">The column name and value pairs.</param> public static void AddRetrieveMultiple <T>(this OrganizationRequestCollection requests, Expression <Func <T, object> > anonymousTypeInitializer, params object[] columnNameAndValuePairs) where T : Entity { requests.Add(new RetrieveMultipleRequest { Query = QueryExpressionFactory.Create(anonymousTypeInitializer, columnNameAndValuePairs), }); }
// ReSharper disable once UnusedParameter.Local private static void AssertExistsWhere <T>(T entity, object[] columnNameAndValuePairs) where T : Entity { if (entity == null) { throw new InvalidOperationException("No " + EntityHelper.GetEntityLogicalName <T>() + " found where " + QueryExpressionFactory.Create <T>((ColumnSet)null, true, columnNameAndValuePairs).GetSqlStatement()); } }
/// <summary> /// Gets first 5000 Active Entities (with the given subset of columns only) /// where the columnNameAndValue Pairs match /// </summary> /// <typeparam name="T">Type of Entity List to return</typeparam> /// <param name="service"></param> /// <param name="columnSet">Columns to retrieve</param> /// <param name="columnNameAndValuePairs">List of pairs that look like this: /// (string name of the column, value of the column) ie. "name", "John Doe" </param> /// <returns></returns> public static List <T> GetEntities <T>(this IOrganizationService service, ColumnSet columnSet, params object[] columnNameAndValuePairs) where T : Entity { return(service.GetEntities(QueryExpressionFactory.Create <T>(columnSet, columnNameAndValuePairs))); }
/// <summary> /// Gets all Entities where the columnNameAndValue Pairs match /// </summary> /// <typeparam name="T">Type of Entity List to return</typeparam> /// <param name="service"></param> /// <param name="columnNameAndValuePairs">List of pairs that look like this: /// (string name of the column, value of the column) ie. "name", "John Doe" </param> /// <returns></returns> public static IEnumerable <T> GetAllEntities <T>(this IOrganizationService service, params object[] columnNameAndValuePairs) where T : Entity { return(service.GetAllEntities(QueryExpressionFactory.Create <T>(columnNameAndValuePairs))); }
/// <summary> /// Gets first 5000 Active Entities (with the given subset of columns only) /// where the columnNameAndValue Pairs match /// </summary> /// <param name="service"></param> /// <param name="logicalName">LogicalName of the Entity.</param> /// <param name="columnSet">Columns to retrieve</param> /// <param name="columnNameAndValuePairs">List of pairs that look like this: /// (string name of the column, value of the column) ie. "name", "John Doe" </param> /// <returns></returns> public static List <Entity> GetEntities(this IOrganizationService service, string logicalName, ColumnSet columnSet, params object[] columnNameAndValuePairs) { return(service.GetEntities <Entity>(QueryExpressionFactory.Create(logicalName, columnSet, columnNameAndValuePairs))); }
/// <summary> /// Gets first 5000 active entities where the values are in the columnName. /// </summary> /// <typeparam name="T">Type of Entity List to return.</typeparam> /// <param name="service">The service.</param> /// <param name="columnName">The name of the column to perform the in against.</param> /// <param name="values">The list of values to search for being in the column name.</param> /// <returns></returns> public static List <T> GetEntitiesIn <T>(this IOrganizationService service, string columnName, IEnumerable values) where T : Entity { return(service.RetrieveList <T>(QueryExpressionFactory.CreateIn <T>(columnName, values))); }
/// <summary> /// Gets first 5000 active entities (with the given subset of columns only) /// where the values are in the columnName /// </summary> /// <typeparam name="T">Type of Entity List to return.</typeparam> /// <param name="service">The service.</param> /// <param name="columnSet">Columns to Return</param> /// <param name="columnName">The name of the column to perform the in against.</param> /// <param name="values">The list of values to search for being in the column name.</param> /// <returns></returns> public static List <T> GetEntitiesIn <T>(this IOrganizationService service, ColumnSet columnSet, string columnName, params object[] values) where T : Entity { return(service.RetrieveList <T>(QueryExpressionFactory.CreateIn <T>(columnSet, columnName, values))); }
/// <summary> /// Performs an Asynchronous delete, deleting entities that are in the given set of values /// Use the querySet overload if performing multiple deletes. /// </summary> /// <typeparam name="T">Type of Entity List to delete.</typeparam> /// <param name="service">The service.</param> /// <param name="columnName">The name of the column to perform the in against.</param> /// <param name="values">The list of values to search for being in the column name.</param> /// <returns></returns> public static BulkDeleteResult DeleteIn <T>(this IOrganizationService service, string columnName, params object[] values) where T : Entity { return(BulkDelete.Delete(service, new QueryExpression[] { QueryExpressionFactory.CreateIn <T>((ColumnSet)null, false, columnName, values) })); }
/// <summary> /// Gets all active entities where the values are in the columnName. /// </summary> /// <typeparam name="T">Type of Entity List to return.</typeparam> /// <param name="service">The service.</param> /// <param name="columnName">The name of the column to perform the in against.</param> /// <param name="values">The list of values to search for being in the column name.</param> /// <returns></returns> public static IEnumerable <T> GetAllEntitiesIn <T>(this IOrganizationService service, string columnName, params object[] values) where T : Entity { return(service.RetrieveAllList <T>(QueryExpressionFactory.CreateIn <T>(columnName, values))); }
/// <summary> /// Creates a query expression, containing a criteria for the specified columnNameAndValuePairs /// </summary> /// <param name="columnNameAndValuePairs">List of pairs that look like this: /// (string name of the column, value of the column) ie. "name","John Doe" goes to entity.name = "John Doe"</param> /// <returns></returns> public QueryExpression CreateExpression(params object[] columnNameAndValuePairs) { return(QueryExpressionFactory.Create <T>(this, columnNameAndValuePairs)); }
/// <summary> /// Creates a query expression. /// </summary> /// <returns></returns> public QueryExpression CreateExpression() { return(QueryExpressionFactory.Create <T>(this)); }
/// <summary> /// Creates a query expression, containing a criteria for the specified in values /// </summary> /// <param name="columnName">The name of the column to perform the in against</param> /// <param name="values">The list of values to search for being in the column name</param> /// <returns></returns> public QueryExpression CreateInExpression(string columnName, params object[] values) { return(QueryExpressionFactory.CreateIn <T>(this, columnName, values)); }
/// <summary> /// Performs an Asynchronous delete, deleting entities that match the given set of name value pairs /// Use the querySet overload if performing multiple deletes /// </summary> /// <typeparam name="T">The type of Entity</typeparam> /// <param name="service">The service.</param> /// <param name="columnNameAndValuePairs">The column name and value pairs.</param> /// <returns></returns> public static BulkDeleteResult Delete <T>(this IOrganizationService service, params object[] columnNameAndValuePairs) where T : Entity { return(BulkDelete.Delete(service, new QueryExpression[] { QueryExpressionFactory.Create <T>(columnNameAndValuePairs) })); }
/// <summary> /// Gets all Active Entities (with the given subset of columns only) /// where the values are in the columnName /// </summary> /// <typeparam name="T">Type of Entity List to return.</typeparam> /// <param name="service"></param> /// <param name="columnSet">Columns to Return.</param> /// <param name="columnName">The name of the column to perform the in against.</param> /// <param name="values">The list of values to search for being in the column name.</param> /// <returns></returns> public static IEnumerable <T> GetAllEntitiesIn <T>(this IOrganizationService service, ColumnSet columnSet, string columnName, IEnumerable values) where T : Entity { return(RetrieveAllEntities <T> .GetAllEntities(service, QueryExpressionFactory.CreateIn <T>(columnSet, columnName, values))); }