public T Get <T>(T entity)
            where T : Entity
        {
            string expand             = ComposeExpands(entity);
            SOAPLikeEntityAPI <T> api = new SOAPLikeEntityAPI <T>(CurrentConfiguration);

            if (entity.ID.HasValue)
            {
                T resultByID = api.GetById(entity.ID, expand: expand);
                resultByID.ReturnBehavior = entity.ReturnBehavior;
                return(resultByID);
            }
            string filter = ComposeFilter(entity);
            var    list   = api.GetList(filter: filter);

            if (list.Count > 1)
            {
                throw new Exception("More than one entity satisfies the condition.");
            }
            if (list.Count == 0)
            {
                throw new Exception("No entities satisfy the condition.");
            }
            T result = api.GetById(list[0].ID, expand: expand);

            result.ReturnBehavior = entity.ReturnBehavior;
            return(result);
        }
        public T[] GetList <T>(T entity, int?top = null, int?skip = null)
            where T : Entity
        {
            string expand             = ComposeExpands(entity);
            SOAPLikeEntityAPI <T> api = new SOAPLikeEntityAPI <T>(CurrentConfiguration);

            string filter = ComposeFilterForGetList(entity);
            var    result = api.GetList(filter: filter, expand: expand, skip: skip, top: top);

            return(result.ToArray());
        }
Exemple #3
0
        public T Get <T>(T entity)
            where T : Entity
        {
            string expand             = ComposeExpands(entity);
            SOAPLikeEntityAPI <T> api = new SOAPLikeEntityAPI <T>(CurrentConfiguration);

            if (entity.ID.HasValue)
            {
                return(api.GetById(entity.ID, expand: expand));
            }
            string filter = ComposeFilter(entity);
            var    result = api.GetList(filter: filter);

            if (result.Count > 1)
            {
                throw new Exception("More than one entity satisfies the condition.");
            }

            return(api.GetById(result.FirstOrDefault().ID, expand: expand));
        }