示例#1
0
        /// <inheritdoc />
        public virtual object GetById(string connectorName, string tableName, ILoggingService loggingService, params object[] id)
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET, id);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);
            var data = resource.GetResourceRecordById(id);

            return(data);
        }
示例#2
0
        /// <inheritdoc />
        public virtual TViewModel GetById <TViewModel>(string connectorName, string tableName, ILoggingService loggingService, params object[] id) where TViewModel : class
        {
            loggingService?.AddTableToLogger(connectorName, tableName, HttpMethodType.GET, id);

            //Manually $expand to prevent nulls on non pk joins
            var joinProperties = typeof(TViewModel).GetProperties()
                                 .Where(c => (c.PropertyType.IsClass && c.PropertyType != typeof(string)) ||
                                        (c.PropertyType.IsGenericType && c.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
                                 .Select(c => c.Name);

            IOperationResource resource = ResourceFactory.GetResource(connectorName, OperationType.read, tableName);

            if (joinProperties.Any())
            {
                return(resource.GetResourceRecordById <TViewModel>(id, new Dictionary <string, string>()
                {
                    { "$expand", string.Join(",", joinProperties) }
                }));
            }
            else
            {
                return(resource.GetResourceRecordById <TViewModel>(id, new Dictionary <string, string>()));
            }
        }