public static Include <T> AppendModelFieldsIfEmpty <T>(this Include <T> include, IModel model) where T : class { void appendModelFieldsRecursive(ChainNode node) { foreach (var n in node.Children) { appendModelFieldsRecursive(n.Value); } var entityType = model.FindEntityType(node.Type); if (entityType != null) { var properties = entityType.GetProperties(); if (!node.HasLeafs()) { foreach (var p in properties) { node.AddChild(p.PropertyInfo); } } } } var root = include.CreateChainNode(); appendModelFieldsRecursive(root); var @value = root.ComposeInclude <T>(); return(@value); }
public static Include <T> Clone <T>(Include <T> include) where T : class { var rootNode = include.CreateChainNode(); var @cloned = rootNode.ComposeInclude <T>(); return(@cloned); }
public static Include <T> ExtractNavigations <T>(this Include <T> include, IModel model) where T : class { void extractNavigationsAppendKeyLeafsRecursive(ChainNode source, ChainNode destination) { var entityType = model.FindEntityType(source.Type); if (entityType != null) { var navigationPropertyInfos = entityType.GetNavigations().Select(e => e.PropertyInfo).ToList(); foreach (var n in source.Children) { var child = n.Value; var propertyInfo = navigationPropertyInfos.FirstOrDefault(e => e.Name == child.MemberName); if (propertyInfo != null) { var childDestination = child.CloneChainMemberNode(destination); //childDestination.AddChild(propertyInfo); extractNavigationsAppendKeyLeafsRecursive(child, childDestination); } } } } var root = include.CreateChainNode(); var destinaion = new ChainNode(root.Type); extractNavigationsAppendKeyLeafsRecursive(root, destinaion); var @value = destinaion.ComposeInclude <T>(); return(@value); }
public static IReadOnlyCollection <ChainNode> ListLeafPaths <T>(this Include <T> include, Type type) { var rootNode = include.CreateChainNode(); var @paths = ChainNodeTree.ListLeafPaths(rootNode); return(@paths); }
/// <summary> /// Set to null all properties except included /// </summary> /// <typeparam name="T"></typeparam> /// <param name="entity"></param> /// <param name="include"></param> public static void Detach <T>(T entity, Include <T> include) where T : class { var chainNode = include.CreateChainNode(); var paths = ChainNodeTree.ListLeafKeyPaths(chainNode); DetachRecursive(entity, paths); }
public static IReadOnlyCollection <Type> ListLeafTypes <T>(this Include <T> include) { var node = include.CreateChainNode(); var @types = node.ListLeafTypes(); return(@types); }
public static void CopyAll <TCol, T>(TCol source, TCol destination, Include <T> include = null, Func <ChainNode, IEnumerable <MemberInfo> > leafRule = null) where TCol : IEnumerable <T> { var node = include.CreateChainNode(); var nodes = node.Children.Values; ChainNodeExtensions.CopyNodes(source, destination, node, nodes, leafRule); }
public static bool IsSubsetOf <T>(this Include <T> include1, Include <T> include2) { var rootNode1 = include1.CreateChainNode(); var rootNode2 = include2.CreateChainNode(); bool @value = ChainNodeTree.IsSubTreeOf(rootNode1, rootNode2); return(@value); }
public static Include <T> Merge <T>(this Include <T> include1, Include <T> include2) { var rootNode1 = include1.CreateChainNode(); var rootNode2 = include2.CreateChainNode(); var union = ChainNodeTree.Merge(rootNode1, rootNode2); var @value = union.ComposeInclude <T>(); return(@value); }
public static bool Equals <T>(T entity1, T entity2, Include <T> include = null) { IEnumerable <ChainMemberNode> nodes = new List <ChainMemberNode>(); if (include != null) { nodes = include.CreateChainNode().Children.Values; } return(ChainNodeExtensions.EqualsNodes(entity1, entity2, nodes)); }
public static void DetachAll <TCol, T>(IEnumerable <T> entities, Include <T> include) where TCol : IEnumerable <T> { var chainNode = include.CreateChainNode(); var paths = ChainNodeTree.ListLeafKeyPaths(chainNode); foreach (var entity in entities) { if (entity != null) { DetachRecursive(entity, paths); } } }
public static IReadOnlyCollection <string> ListXPaths <T>(this Include <T> include) { if (include == null) { return new List <string> { "/" } } ; var rootNode = include.CreateChainNode(); var @paths = ChainNodeTree.ListXPaths(rootNode); return(@paths); }
public RulesDictionary <TEntity> SubTree( Include <TEntity> include, Action <RulesSubDictionary <TEntity> > config = null, bool?useToString = null, string dateTimeFormat = null, string floatingPointFormat = null, bool?stringAsJsonLiteral = null, bool?stringJsonEscape = null, Func <StringBuilder, bool> nullSerializer = null, bool?handleNullProperty = null, InternalNodeOptions internalNodeOptions = null ) { if (include == null) { throw new ArgumentNullException(nameof(include), "Serialization for subset can't be configured if subset is defined for the root only include (include is null)"); } var subDictionary = new RulesSubDictionary <TEntity>( include.CreateChainNode(), useToString ?? this.useToString, dateTimeFormat ?? this.dateTimeFormat, floatingPointFormat ?? this.floatingPointFormat, stringAsJsonLiteral ?? false, stringJsonEscape ?? true, nullSerializer ?? this.nullSerializer, handleNullProperty ?? this.handleNullProperty, internalNodeOptions ?? this.internalNodeOptions, compile: compile ); config?.Invoke(subDictionary); subtrees.Add(subDictionary); return(this); }