Example #1
0
        /// <summary>
        ///     Creates an entity reference for the type specified.
        /// </summary>
        /// <param name="type">
        ///     The entity type.
        /// </param>
        /// <returns>
        ///     The newly created entity reference.
        /// </returns>
        internal EntityReference CreateEntityReference(Type type)
        {
            if (type == null || type == typeof(object))
            {
                return(null);
            }

            var inspector = Inspector.InspectorForType(type);

            if (inspector == null)
            {
                return(null);
            }

            var entityReference = this.CreateEntityReference(inspector);

            if (entityReference == null && type.IsInterface)
            {
                type = TypeFinder.GetCommonBaseType(this.CommonBaseTypeCandidatesForType(type)
                                                    .Where(t => t != null && t != typeof(object)).Distinct());
                return(this.CreateEntityReference(type));
            }

            return(entityReference);
        }
Example #2
0
 /// <summary>
 ///     Gets the common base type candidates for a given type.
 /// </summary>
 /// <param name="type">
 ///     The entity type.
 /// </param>
 /// <returns>
 ///     The common base type candidates.
 /// </returns>
 protected virtual IEnumerable <Type> CommonBaseTypeCandidatesForType(Type type)
 {
     return(new[]
     {
         TypeFinder.GetCommonBaseType(this.keyBindings.Keys.Where(type.IsAssignableFrom)),
         TypeFinder.GetCommonBaseType(this.tableBindings.Keys.Where(type.IsAssignableFrom)),
         TypeFinder.GetCommonBaseType(this.columnBindings.Keys.Where(type.IsAssignableFrom))
     });
 }
Example #3
0
        /// <summary>
        ///     Gets the common base type candidates for a given type.
        /// </summary>
        /// <param name="type">
        ///     The entity type.
        /// </param>
        /// <returns>
        ///     The common base type candidates.
        /// </returns>
        protected override IEnumerable <Type> CommonBaseTypeCandidatesForType(Type type)
        {
            var candidates = base.CommonBaseTypeCandidatesForType(type);

            if (this.StrictExplicitColumnBinding || this.StrictExplicitTableBinding)
            {
                return(candidates);
            }

            var candidate = TypeFinder.GetCommonBaseType(this.entityReferences.Keys.Where(type.IsAssignableFrom));

            return(candidates.Concat(new[] { candidate }));
        }
Example #4
0
        /// <summary>
        ///     Determines whether the database contains any entities of the types specified.
        /// </summary>
        /// <param name="entityTypes">
        ///     The entity types.
        /// </param>
        /// <returns>
        ///     <c>true</c> if the there are any entities; otherwise <c>false</c>.
        /// </returns>
        public bool Any(IEnumerable <Type> entityTypes)
        {
            if (entityTypes == null)
            {
                throw new ArgumentNullException(nameof(entityTypes));
            }

            this.ThrowIfDisposed();
            var types    = entityTypes.ToArray();
            var scanSpec = this.entityContext.ScanSpecForType(types);

            scanSpec.MaxCells = 1;
            var entities = this.Fetch(TypeFinder.GetCommonBaseType(types), scanSpec, Behaviors.DoNotCache);

            return(entities != null && entities.OfType <object>().Any());
        }