Beispiel #1
0
        private static ICypherFluentQuery CommonCreate <T>(
            this ICypherFluentQuery query
            , T entity
            , CreateOptions options
            , Func <string, string> getFinalCql) where T : class
        {
            if (options == null)
            {
                options = new CreateOptions();
            }

            var createProperties      = GetCreateProperties(entity);
            var identifier            = entity.EntityParamKey(options.Identifier);
            var intermediateCreateCql = GetMatchWithParam(identifier, entity.EntityLabel(), createProperties.Count > 0 ? identifier : "");

            var createCql = getFinalCql(intermediateCreateCql);

            var dynamicOptions = new CreateDynamicOptions {
                IgnoreNulls = true
            };                                                                    // working around some buug where null properties are blowing up. don't care on create.
            var cutdownEntity = entity.CreateDynamic(createProperties, dynamicOptions);

            query = query.Create(createCql);

            if (createProperties.Count > 0)
            {
                query = query.WithParam(identifier, cutdownEntity);
            }

            return(query);
        }
Beispiel #2
0
        private static ICypherFluentQuery CommonMerge <T>(
            this ICypherFluentQuery query
            , T entity
            , string key
            , string mergeCql
            , List <CypherProperty> mergeOverride    = null
            , List <CypherProperty> onMatchOverride  = null
            , List <CypherProperty> onCreateOverride = null) where T : class
        {
            //A merge requires the properties of both merge, create and match in the cutdown object
            var mergeProperties  = mergeOverride ?? CypherTypeItemHelper.PropertiesForPurpose <T, CypherMergeAttribute>(entity);
            var createProperties = GetCreateProperties(entity, onCreateOverride);
            var matchProperties  = onMatchOverride ?? CypherTypeItemHelper.PropertiesForPurpose <T, CypherMergeOnMatchAttribute>(entity);

            dynamic mergeObjectParam = entity.CreateDynamic(mergeProperties);
            var     matchParamName   = GetMatchParamName(key);

            query = query.Merge(mergeCql);
            query = query.WithParam(matchParamName, mergeObjectParam);

            if (matchProperties.Count > 0)
            {
                var entityType = entity.GetType();
                foreach (var matchProperty in matchProperties)
                {
                    var propertyParam = key + matchProperty.JsonName;
                    var propertyValue = GetValue(entity, matchProperty, entityType);
                    query = query.OnMatch().Set(GetSetWithParamCql(key, matchProperty.JsonName, propertyParam));
                    query = query.WithParam(propertyParam, propertyValue);
                }
            }

            if (createProperties.Count > 0)
            {
                var     createParamName   = key + "OnCreate";
                dynamic createObjectParam = entity.CreateDynamic(createProperties);
                query = query.OnCreate().Set(GetSetWithParamCql(key, createParamName));
                query = query.WithParam(createParamName, createObjectParam);
            }

            return(query);
        }