Esempio n. 1
0
        public static ICypherFluentQuery MergeEntity <T>(this ICypherFluentQuery query, T entity, string paramKey = null, List <CypherProperty> mergeOverride = null, List <CypherProperty> onMatchOverride = null, List <CypherProperty> onCreateOverride = null, string preCql = "", string postCql = "") where T : class
        {
            paramKey = entity.EntityParamKey(paramKey);
            var context = CypherExtensionContext.Create(query);
            var cypher1 = entity.ToCypherString <T, CypherMergeAttribute>(context, paramKey, mergeOverride);
            var cql     = string.Format("{0}({1}){2}", preCql, cypher1, postCql);

            return(query.CommonMerge(entity, paramKey, cql, mergeOverride, onMatchOverride, onCreateOverride));
        }
Esempio n. 2
0
        public static ICypherFluentQuery MergeRelationship <T>(this ICypherFluentQuery query, T entity, List <CypherProperty> mergeOverride = null, List <CypherProperty> onMatchOverride = null, List <CypherProperty> onCreateOverride = null) where T : BaseRelationship
        {
            //Eaxctly the same as a merge entity except the cql is different
            var cql = GetRelationshipCql(
                entity.FromKey
                , entity.ToCypherString <T, CypherMergeAttribute>(CypherExtensionContext.Create(query), entity.Key, mergeOverride)
                , entity.ToKey);

            return(query.CommonMerge(entity, entity.Key, cql, mergeOverride, onMatchOverride, onCreateOverride));
        }
Esempio n. 3
0
        private static ICypherFluentQuery MatchWorker <T>(this ICypherFluentQuery query, T entity, MatchOptions options, Func <ICypherFluentQuery, string, ICypherFluentQuery> matchFunction) where T : class
        {
            var     identifier  = entity.EntityParamKey(options.Identifier);
            var     matchCypher = entity.ToCypherString <T, CypherMatchAttribute>(CypherExtensionContext.Create(query), identifier, options.MatchOverride);
            var     cql         = string.Format("{0}({1}){2}", options.PreCql, matchCypher, options.PostCql);
            dynamic cutdown     = entity.CreateDynamic(options.MatchOverride ?? CypherTypeItemHelper.PropertiesForPurpose <T, CypherMatchAttribute>(entity));

            var matchKey = GetMatchParamName(identifier);

            return(matchFunction(query, cql)
                   .WithParam(matchKey, cutdown));
        }
Esempio n. 4
0
        private static ICypherFluentQuery MatchRelationshipWorker <T>(
            this ICypherFluentQuery query
            , T relationship
            , MatchRelationshipOptions options
            , Func <ICypherFluentQuery, string, ICypherFluentQuery> matchFunction) where T : BaseRelationship
        {
            var matchProperties = options.MatchOverride ?? CypherTypeItemHelper.PropertiesForPurpose <T, CypherMatchAttribute>(relationship);
            var cql             = GetRelationshipCql(
                relationship.FromKey
                , relationship.ToCypherString <T, CypherMatchAttribute>(CypherExtensionContext.Create(query), relationship.Key, matchProperties)
                , relationship.ToKey);

            return(matchFunction(query, cql));
        }
Esempio n. 5
0
 internal static List <CypherProperty> UseProperties <T>(this T entity, CypherExtensionContext context, params Expression <Func <T, object> >[] properties)
     where T : class
 {
     //Cache the T entity properties into a dictionary of strings
     if (properties != null)
     {
         return(properties.ToList().Where(x => x != null).Select(x =>
         {
             var memberExpression = x.Body as MemberExpression ?? ((UnaryExpression)x.Body).Operand as MemberExpression;
             return memberExpression == null ? null : memberExpression.Member.Name;
         }).Select(x => new CypherProperty {
             TypeName = x, JsonName = x.ApplyCasing(context)
         }).ToList());
     }
     return(new List <CypherProperty>());
 }
Esempio n. 6
0
        public static ICypherFluentQuery MergeEntity <T>(this ICypherFluentQuery query, T entity, MergeOptions options) where T : class
        {
            var    context = CypherExtensionContext.Create(query);
            string pattern;

            if (options.MergeViaRelationship != null)
            {
                var relationshipSegment = GetAliasLabelCql(string.Empty, options.MergeViaRelationship.EntityLabel());

                pattern = GetRelationshipCql(
                    options.MergeViaRelationship.FromKey
                    , relationshipSegment
                    , GetAliasLabelCql(options.MergeViaRelationship.ToKey, entity.EntityLabel()));
            }
            else
            {
                pattern = entity.ToCypherString <T, CypherMergeAttribute>(context, options.Identifier, options.MergeOverride);
            }
            var wrappedPattern = string.Format("{0}({1}){2}", options.PreCql, pattern, options.PostCql);

            return(query.CommonMerge(entity, options.Identifier, wrappedPattern, options.MergeOverride, options.OnMatchOverride, options.OnCreateOverride));
        }
 public CypherExtensionTestHelper()
 {
     CypherExtensionContext = new CypherExtensionContext();
 }
 public ConfigWith(CypherExtensionContext context, string label = null)
 {
     _label   = label;
     _context = context;
 }
 public static FluentConfig Config(CypherExtensionContext context = null)
 {
     return(new FluentConfig(context ?? new CypherExtensionContext()));
 }
 private FluentConfig(CypherExtensionContext context)
 {
     _context = context;
 }