Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        protected SqlStatementCreator(EntityType entityType, EntityField[] fields)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            // set...
            _entityType = entityType;

            // mjr - 12-10-2005 - setup the dialect...
            if (entityType.HasDatabaseName)
            {
                // mjr - 12-10-2005 - this needs to be refactored (not ideal)...
                using (IConnection connection = Database.CreateConnection(entityType.DatabaseName))
                    this.Dialect = connection.Dialect;
            }
            else
            {
                Dialect = Database.DefaultDialect;
            }

            // set...
            if (Dialect == null)
            {
                throw new InvalidOperationException("Dialect is null.");
            }

            // do the fields...
            _fields = new EntityFieldCollection(entityType);

            // mbr - 16-10-2005 - now done on demand...
            //			if(fields.Length == 0)
            //			{
            //				// get default fields...
            //				fields = entityType.GetCommonFields();
            //				if(fields.Length == 0)
            //				{
            //					fields = entityType.GetKeyFields();
            //					if(fields.Length == 0)
            //						throw new InvalidOperationException(string.Format("Entity type '{0}' has no common fields and no key fields.", entityType));
            //				}
            //			}

            // add the ones passed into the constructor...
            _fields.AddRange(fields);

            // order...
            _sortOrder = entityType.DefaultSortOrder.Clone();
            this.FirstApplySortCall = true;

            this.ArrayParameterType = Database.ArrayParameterType;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the default fields.
        /// </summary>
        /// <returns></returns>
        protected virtual void GetDefaultFields(EntityFieldCollection fields)
        {
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            // common...
            fields.AddRange(this.EntityType.GetCommonFields());
            if (fields.Count == 0)
            {
                fields.AddRange(this.EntityType.GetKeyFields());
                if (fields.Count == 0)
                {
                    throw new InvalidOperationException(string.Format("Entity type '{0}' has no common fields and no key fields.", this.EntityType));
                }
            }

            // mbr - 10-10-2007 - case 875 - add joined names...
            if (this.HasJoins)
            {
                foreach (SqlJoin join in this.Joins)
                {
                    // mbr - 2011-08-30 - include?
                    if (join.IncludeInTreeFetch)
                    {
                        if (join.TargetEntityType == null)
                        {
                            throw new InvalidOperationException("join.TargetEntityType is null.");
                        }

                        this.MergeFields(fields, join.TargetEntityType.GetCommonFields());
                    }
                }
            }
        }