Exemple #1
0
        public static void GetChild <T>(this SQLiteConnection conn, ref T element, PropertyInfo relationshipProperty)
        {
            var relationshipAttribute = relationshipProperty.GetAttribute <RelationshipAttribute>();

            if (relationshipAttribute is OneToOneAttribute)
            {
                conn.GetOneToOneChild(ref element, relationshipProperty);
            }
            else if (relationshipAttribute is OneToManyAttribute)
            {
                conn.GetOneToManyChildren(ref element, relationshipProperty);
            }
            else if (relationshipAttribute is ManyToOneAttribute)
            {
                conn.GetManyToOneChild(ref element, relationshipProperty);
            }
            else if (relationshipAttribute is ManyToManyAttribute)
            {
                conn.GetManyToManyChildren(ref element, relationshipProperty);
            }
            else if (relationshipAttribute is TextBlobAttribute)
            {
                TextBlobOperations.GetTextBlobChild(ref element, relationshipProperty);
            }
        }
Exemple #2
0
        public static void SetChildren <T>(this SQLiteConnection conn, IEnumerable <T> elements, params string[] relationshipPropertyNames) where T : new()
        {
            if (elements is ITableQuery <T> )
            {
                throw new InvalidOperationException("Use WithChildren<T> or enumerate the query before calling SetChildren<T>.");
            }

            var results = elements as ICollection <T> ?? elements.ToList();

            var relationshipProperties = typeof(T).GetRelationshipProperties().ToList();

            if (relationshipPropertyNames != null && relationshipPropertyNames.Any())
            {
                foreach (var propertyName in relationshipPropertyNames)
                {
                    if (relationshipProperties.All(p => p.Name != propertyName))
                    {
                        throw new ArgumentException(String.Format("Invalid relationship property name '{0}'.", propertyName));
                    }
                }

                var toRemove = relationshipProperties.Where(p => !relationshipPropertyNames.Contains(p.Name)).ToList();

                foreach (var p in toRemove)
                {
                    relationshipProperties.Remove(p);
                }
            }

            foreach (var relationshipProperty in relationshipProperties)
            {
                var relationshipAttribute = relationshipProperty.GetAttribute <RelationshipAttribute>();

                if (relationshipAttribute is ManyToOneAttribute)
                {
                    conn.GetManyToOneChildren(results, relationshipProperty);
                }
                else if (relationshipAttribute is OneToManyAttribute)
                {
                    conn.GetOneToManyChildren(results, relationshipProperty);
                }
#if DEBUG
                else
                {
                    Debug.WriteLine("WARNING: RelationshipAttribute {0} is not yet supported by WithChildren or SetChildren.", relationshipAttribute.GetType().Name);
                }
#endif
            }
        }