Ejemplo n.º 1
0
        /// <summary>
        ///     Registers a table binding for the type specified.
        /// </summary>
        /// <param name="type">
        ///     The entity type.
        /// </param>
        /// <param name="tableBinding">
        ///     The key binding.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the table binding has been added, <c>false</c> if an existing table binding has been replaced.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="type" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="tableBinding" /> is null.
        /// </exception>
        public bool RegisterTableBinding(Type type, ITableBinding tableBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException(nameof(tableBinding));
            }

            lock (this.syncRoot)
            {
                this.Refresh();

                BindingSpec <ITableBinding> existingTableBinding;
                if (this.tableBindings.TryGetValue(type, out existingTableBinding))
                {
                    this.RemovingTableBinding(type, existingTableBinding.Binding);
                }

                this.tableBindings.Remove(from kv in this.tableBindings
                                          where kv.Value.Derived && type.IsAssignableFrom(kv.Key)
                                          select kv.Key);
                return(this.tableBindings.AddOrUpdate(type, new BindingSpec <ITableBinding>(tableBinding)));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 ///     Removes all entity references affected by the table binding specified.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <param name="tableBinding">
 ///     The table binding.
 /// </param>
 protected override void RemovingTableBinding(Type type, ITableBinding tableBinding)
 {
     this.entityReferences.Remove(
         from kv in this.entityReferences
         where type.IsAssignableFrom(kv.Key) ||
         (kv.Value != null && object.ReferenceEquals(kv.Value.TableBinding, tableBinding))
         select kv.Key);
 }
Ejemplo n.º 3
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityReference" /> class.
        /// </summary>
        /// <param name="entityReference">
        ///     The entity reference.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityReference" /> is null.
        /// </exception>
        internal EntityReference(EntityReference entityReference)
        {
            if (entityReference == null)
            {
                throw new ArgumentNullException(nameof(entityReference));
            }

            this.entityType    = entityReference.entityType;
            this.tableBinding  = entityReference.tableBinding;
            this.columnBinding = entityReference.columnBinding;
            this.keyBinding    = entityReference.keyBinding;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Gets the table binding associated with the specified type.
        /// </summary>
        /// <param name="type">
        ///     The type.
        /// </param>
        /// <param name="tableBinding">
        ///     When this method returns, contains the table binding associated with the specified type, if the type is found;
        ///     otherwise null.
        /// </param>
        /// <returns>
        ///     <c>true</c> if a table binding exists for the type specified; otherwise, <c>false</c>.
        /// </returns>
        public bool TryGetTableBinding(Type type, out ITableBinding tableBinding)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            lock (this.syncRoot)
            {
                tableBinding = this.GetTableBindingForType(type);
            }

            return(tableBinding != null);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityReference" /> class.
        /// </summary>
        /// <param name="entityType">
        ///     The entity type.
        /// </param>
        /// <param name="tableBinding">
        ///     The table binding.
        /// </param>
        /// <param name="columnBinding">
        ///     The column binding.
        /// </param>
        /// <param name="keyBinding">
        ///     The key binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="entityType" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="tableBinding" /> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     If <paramref name="keyBinding" /> is null.
        /// </exception>
        internal EntityReference(Type entityType, ITableBinding tableBinding, IColumnBinding columnBinding,
                                 IKeyBinding keyBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException(nameof(entityType));
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException(nameof(tableBinding));
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException(nameof(keyBinding));
            }

            this.entityType    = entityType;
            this.tableBinding  = tableBinding;
            this.columnBinding = columnBinding;
            this.keyBinding    = keyBinding;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Removes all entity references affected by the table binding specified.
 /// </summary>
 /// <param name="type">
 /// The entity type.
 /// </param>
 /// <param name="tableBinding">
 /// The table binding.
 /// </param>
 protected override void RemovingTableBinding(Type type, ITableBinding tableBinding)
 {
     this.entityReferences.Remove(
         from kv in this.entityReferences where type.IsAssignableFrom(kv.Key) || (kv.Value != null && object.ReferenceEquals(kv.Value.TableBinding, tableBinding)) select kv.Key);
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     The removing table binding callback.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <param name="tableBinding">
 ///     The table binding.
 /// </param>
 protected virtual void RemovingTableBinding(Type type, ITableBinding tableBinding)
 {
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReference"/> class.
        /// </summary>
        /// <param name="entityType">
        /// The entity type.
        /// </param>
        /// <param name="tableBinding">
        /// The table binding.
        /// </param>
        /// <param name="columnBinding">
        /// The column binding.
        /// </param>
        /// <param name="keyBinding">
        /// The key binding.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityType"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="tableBinding"/> is null.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="keyBinding"/> is null.
        /// </exception>
        internal EntityReference(Type entityType, ITableBinding tableBinding, IColumnBinding columnBinding, IKeyBinding keyBinding)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            if (tableBinding == null)
            {
                throw new ArgumentNullException("tableBinding");
            }

            if (keyBinding == null)
            {
                throw new ArgumentNullException("keyBinding");
            }

            this.entityType = entityType;
            this.tableBinding = tableBinding;
            this.columnBinding = columnBinding;
            this.keyBinding = keyBinding;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReference"/> class.
        /// </summary>
        /// <param name="entityReference">
        /// The entity reference.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityReference"/> is null.
        /// </exception>
        internal EntityReference(EntityReference entityReference)
        {
            if (entityReference == null)
            {
                throw new ArgumentNullException("entityReference");
            }

            this.entityType = entityReference.entityType;
            this.tableBinding = entityReference.tableBinding;
            this.columnBinding = entityReference.columnBinding;
            this.keyBinding = entityReference.keyBinding;
        }