Exemplo n.º 1
0
        /// <summary>
        /// Selects the projection fields directly from the index
        /// </summary>
        /// <typeparam name="TProjection">The type of the projection.</typeparam>
        public IDocumentQuery <TProjection> SelectFields <TProjection>()
        {
            var propertyInfos    = ReflectionUtil.GetPropertiesAndFieldsFor <TProjection>(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance).ToList();
            var projections      = propertyInfos.Select(x => x.Name).ToArray();
            var identityProperty = DocumentConvention.GetIdentityProperty(typeof(TProjection));
            var fields           = propertyInfos.Select(p => (p == identityProperty) ? Constants.Indexing.Fields.DocumentIdFieldName : p.Name).ToArray();

            return(SelectFields <TProjection>(fields, projections));
        }
Exemplo n.º 2
0
        private static IEnumerable <MemberInfo> GetPropertiesForType(Type type)
        {
            foreach (var propertyInfo in ReflectionUtil.GetPropertiesAndFieldsFor(type, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic))
            {
                yield return(propertyInfo);
            }

            foreach (var @interface in type.GetInterfaces())
            {
                foreach (var propertyInfo in GetPropertiesForType(@interface))
                {
                    yield return(propertyInfo);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Refreshes the specified entity from Raven server.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="entity">The entity.</param>
        public void Refresh <T>(T entity)
        {
            DocumentMetadata value;

            if (entitiesAndMetadata.TryGetValue(entity, out value) == false)
            {
                throw new InvalidOperationException("Cannot refresh a transient instance");
            }
            IncrementRequestCount();
            var jsonDocument = DatabaseCommands.Get(value.Key);

            if (jsonDocument == null)
            {
                throw new InvalidOperationException("Document '" + value.Key + "' no longer exists and was probably deleted");
            }

            value.Metadata         = jsonDocument.Metadata;
            value.OriginalMetadata = (RavenJObject)jsonDocument.Metadata.CloneToken();
            value.ETag             = jsonDocument.Etag;
            value.OriginalValue    = jsonDocument.DataAsJson;
            var newEntity = ConvertToEntity(typeof(T), value.Key, jsonDocument.DataAsJson, jsonDocument.Metadata);
            var type      = entity.GetType();

            foreach (var property in ReflectionUtil.GetPropertiesAndFieldsFor(type, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                var prop = property;
                if (prop.DeclaringType != type && prop.DeclaringType != null)
                {
                    prop = prop.DeclaringType.GetProperty(prop.Name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if (prop == null)
                    {
                        prop = property; // shouldn't happen ever...
                    }
                }
                if (!prop.CanWrite() || !prop.CanRead() || prop.GetIndexParameters().Length != 0)
                {
                    continue;
                }
                prop.SetValue(entity, prop.GetValue(newEntity));
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Selects all the projection fields directly from the index
 /// </summary>
 /// <typeparam name="TProjection">The type of the projection.</typeparam>
 public virtual IAsyncDocumentQuery <TProjection> SelectFields <TProjection>()
 {
     return(SelectFields <TProjection>(ReflectionUtil.GetPropertiesAndFieldsFor <TProjection>(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Select(x => x.Name).ToArray()));
 }