Exemple #1
0
        /// <summary>
        /// Gets the first entity that matches the query expression.  Null is returned if none are found.
        /// </summary>
        /// <typeparam name="T">The Entity Type.</typeparam>
        /// <param name="service">The service.</param>
        /// <param name="id">Id of the entity to search for.</param>
        /// <param name="anonymousTypeInitializer">An Anonymous Type Initializer where the properties of the anonymous
        /// type are the column names to add.</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task <T> GetEntityOrDefaultAsync <T>(this IOrganizationServiceAsync2 service, Guid id, Expression <Func <T, object> > anonymousTypeInitializer = null, CancellationToken token = default) where T : Entity
        {
            var idName = EntityHelper.GetIdAttributeName <T>();

            return(anonymousTypeInitializer == null
                ? service.GetFirstOrDefaultAsync <T>(token, idName, id)
                : service.GetFirstOrDefaultAsync(anonymousTypeInitializer, token, idName, id));
        }
Exemple #2
0
        /// <summary>
        /// Gets the entity by id. Null is returned if it isn't found.
        /// </summary>
        /// <param name="service">The service.</param>
        /// <param name="logicalName">Logical name of the entity.</param>
        /// <param name="id">Id of the entity to search for.</param>
        /// <param name="columnSet">Columns to retrieve.</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task <Entity> GetEntityOrDefaultAsync(this IOrganizationServiceAsync2 service, string logicalName, Guid id, ColumnSet columnSet = null, CancellationToken token = default)
        {
            var idName = EntityHelper.GetIdAttributeName(logicalName);

            return(columnSet == null
                ? service.GetFirstOrDefaultAsync(logicalName, token, idName, id)
                : service.GetFirstOrDefaultAsync(logicalName, columnSet, token, idName, id));
        }