/// <summary>
        /// Creates a new Insert Query object which is ready to use.
        /// </summary>
        /// <param name="fields">Array of EntityFieldCore objects to use to build the insert query</param>
        /// <param name="fieldsPersistenceInfo">Array of IFieldPersistenceInfo objects to use to build the insert query</param>
        /// <param name="query">The query object to fill.</param>
        /// <param name="fieldToParameter">Hashtable which will contain after the call for each field the parameter which contains or will contain the field's value.</param>
        /// <remarks>Generic version.</remarks>
        /// <exception cref="System.ArgumentNullException">When fields is null or fieldsPersistenceInfo is null</exception>
        /// <exception cref="System.ArgumentException">When fields contains no EntityFieldCore instances or fieldsPersistenceInfo is empty.</exception>
        /// <exception cref="ORMQueryConstructionException">When there are no fields to insert in the fields list. This exception is to prevent
        /// INSERT INTO table () VALUES () style queries.</exception>
        protected override void CreateSingleTargetInsertDQ(IEntityFieldCore[] fields, IFieldPersistenceInfo[] fieldsPersistenceInfo,
                                                           IActionQuery query, Dictionary <IEntityFieldCore, DbParameter> fieldToParameter)
        {
            TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSingleTargetInsertDQ", "Method Enter");
            QueryFragments fragments = new QueryFragments();

            fragments.AddFormatted("INSERT INTO {0}", this.Creator.CreateObjectName(fieldsPersistenceInfo[0]));
            DelimitedStringList fieldNames = fragments.AddCommaFragmentList(true);

            fragments.AddFragment("VALUES");
            DelimitedStringList valueFragments = fragments.AddCommaFragmentList(true);

            DbParameter newParameter;
            bool        hasIdentity = false;

            for (int i = 0; i < fields.Length; i++)
            {
                IEntityFieldCore      field           = fields[i];
                IFieldPersistenceInfo persistenceInfo = fieldsPersistenceInfo[i];

                if (string.IsNullOrEmpty(persistenceInfo.IdentityValueSequenceName))
                {
                    if (!CheckIfFieldNeedsInsertAction(field))
                    {
                        continue;
                    }
                    fieldNames.Add(this.Creator.CreateFieldNameSimple(persistenceInfo, field.Name));
                    AppendFieldToValueFragmentsForInsert(query, fieldToParameter, valueFragments, field, persistenceInfo);
                }
                else
                {
                    newParameter = this.Creator.CreateParameter(field, persistenceInfo, ParameterDirection.InputOutput);
                    query.AddParameterFieldRelation(field, newParameter, persistenceInfo.TypeConverterToUse, parameterValueCanBeNull: false);
                    query.AddSequenceRetrievalQuery(CreateCommand("SELECT @@IDENTITY", query.Connection), false).AddSequenceParameter(newParameter);
                    hasIdentity = true;
                    fieldToParameter.Add(field, newParameter);
                }
            }
            if (fieldNames.Count <= 0)
            {
                if (hasIdentity)
                {
                    // a table with just 1 identity field, use a special case query: INSERT INTO table values ()
                    fieldNames.Clear();
                    valueFragments.Clear();
                    fragments.AddFragment("()");
                }
                else
                {
                    throw new ORMQueryConstructionException("The insert query doesn't contain any fields.");
                }
            }
            query.SetCommandText(MakeParametersAnonymous(fragments.ToString(), query.Parameters));

            TraceHelper.WriteIf(Switch.TraceVerbose, query, "Generated Sql query");
            TraceHelper.WriteLineIf(Switch.TraceInfo, "CreateSingleTargetInsertDQ", "Method Exit");
        }
Ejemplo n.º 2
0
        public static bool IsChangedEx(this IEntityFieldCore entityFieldCore)
        {
            if (entityFieldCore.IsChanged)
            {
                if (entityFieldCore.DbValue == null)
                {
                    // Ne devrait plus arrivé car ce cas est à présent géré par CommonEntityBase.PreProcessValueToSet
                    // 1er cas : Valeur de type chaine null ou vide
                    if (entityFieldCore.DataType == typeof(string))
                    {
                        string s = entityFieldCore.CurrentValue as string;
                        if (string.IsNullOrEmpty(s))
                        {
                            // La valeur stockée en base est null et la valeur courante est une chaine vide ("")
                            // => identique
                            return(false);
                        }
                    }
                }
                else
                {
                    string currentValueString = GetString(entityFieldCore.CurrentValue);

                    // 2ème cas : Valeur de type chaine identique
                    if (entityFieldCore.DataType == typeof(string))
                    {
                        string dbValueString = GetString(entityFieldCore.DbValue);
                        if (currentValueString.Equals(dbValueString))
                        {
                            return(false);
                        }
                    }

                    // 3ème cas : Valeur double
                    if (IsNumeric(currentValueString))
                    {
                        double currentValueAsDouble = GetDouble(currentValueString);

                        string dbValueString   = GetString(entityFieldCore.DbValue);
                        double dbValueAsDouble = GetDouble(dbValueString);

                        const int NumberOfDecimals = 10;
                        if (Math.Round(currentValueAsDouble, NumberOfDecimals) == Math.Round(dbValueAsDouble, NumberOfDecimals))
                        {
                            // A l'arrondi près, les valeurs sont égales
                            // => identique
                            return(false);
                        }
                    }
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 3
0
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand which is a field.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, Mecca.CMT.DAL.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
 }
Ejemplo n.º 4
0
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand which is a field.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is a derived table.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, DerivedTableDefinition rightOperand, string aliasLeftOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, string.Empty, onClause, leftOperand, rightOperand);
 }
Ejemplo n.º 5
0
 /// <summary>Creates a new dynamic relation instance</summary>
 /// <param name="leftOperand">The left operand.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperandEntityName">Name of the entity, which is used as the right operand.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 /// <returns>ready to use dynamic relation</returns>
 public override IDynamicRelation CreateDynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, string rightOperandEntityName, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     return(new DynamicRelation(leftOperand, joinType, (Northwind.SSDAL.EntityType)Enum.Parse(typeof(Northwind.SSDAL.EntityType), rightOperandEntityName, false), aliasLeftOperand, aliasRightOperand, onClause));
 }
Ejemplo n.º 6
0
 /// <summary>Creates a new dynamic relation instance</summary>
 /// <param name="leftOperand">The left operand.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 /// <returns>ready to use dynamic relation</returns>
 public override IDynamicRelation CreateDynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, DerivedTableDefinition rightOperand, string aliasLeftOperand, IPredicate onClause)
 {
     return(new DynamicRelation(leftOperand, joinType, rightOperand, aliasLeftOperand, onClause));
 }
Ejemplo n.º 7
0
 /// <summary>Creates a new dynamic relation instance</summary>
 /// <param name="leftOperand">The left operand.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperandEntityName">Name of the entity, which is used as the right operand.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 /// <returns>ready to use dynamic relation</returns>
 public override IDynamicRelation CreateDynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, string rightOperandEntityName, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     return(new DynamicRelation(leftOperand, joinType, (SD.LLBLGen.Pro.Examples.Authorization.EntityType)Enum.Parse(typeof(SD.LLBLGen.Pro.Examples.Authorization.EntityType), rightOperandEntityName, false), aliasLeftOperand, aliasRightOperand, onClause));
 }
Ejemplo n.º 8
0
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand which is a field.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, AdventureWorks.Dal.Adapter.v54.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
 }
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand which is a field.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, SD.LLBLGen.Pro.Examples.Auditing.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
 }
Ejemplo n.º 10
0
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand which is a field.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, Snoffleware.LLBLGen.Identity.Core.Data.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
 }
Ejemplo n.º 11
0
 /// <inheritdoc/>
 public override IDynamicRelation CreateDynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, string rightOperandEntityName, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     return(new DynamicRelation(leftOperand, joinType, (Snoffleware.LLBLGen.Identity.Core.Data.EntityType)Enum.Parse(typeof(Snoffleware.LLBLGen.Identity.Core.Data.EntityType), rightOperandEntityName, false), aliasLeftOperand, aliasRightOperand, onClause));
 }
Ejemplo n.º 12
0
		/// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
		/// <param name="leftOperand">The left operand which is a field.</param>
		/// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
		/// <param name="rightOperand">The right operand which is an entity.</param>
		/// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
		/// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
		/// <param name="onClause">The on clause for the join.</param>
		public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, AdventureWorks.Dal.Adapter.v42.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
		{
			this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
		}
Ejemplo n.º 13
0
		/// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
		/// <param name="leftOperand">The left operand which is a field.</param>
		/// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
		/// <param name="rightOperand">The right operand which is a derived table.</param>
		/// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
		/// <param name="onClause">The on clause for the join.</param>
		public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, DerivedTableDefinition rightOperand, string aliasLeftOperand, IPredicate onClause)
		{
			this.InitClass(joinType, aliasLeftOperand, string.Empty, onClause, leftOperand, rightOperand);
		}
 /// <summary>Initializes a new instance of the <see cref="DynamicRelation"/> class.</summary>
 /// <param name="leftOperand">The left operand which is a field.</param>
 /// <param name="joinType">Type of the join. If None is specified, Inner is assumed.</param>
 /// <param name="rightOperand">The right operand which is an entity.</param>
 /// <param name="aliasLeftOperand">The alias of the left operand. If you don't want to / need to alias the left operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="aliasRightOperand">The alias of the right operand. If you don't want to / need to alias the right operand (only alias if you have to), specify string.Empty.</param>
 /// <param name="onClause">The on clause for the join.</param>
 public DynamicRelation(IEntityFieldCore leftOperand, JoinHint joinType, NinjaSoftware.EnioNg.CoolJ.EntityType rightOperand, string aliasLeftOperand, string aliasRightOperand, IPredicate onClause)
 {
     this.InitClass(joinType, aliasLeftOperand, aliasRightOperand, onClause, leftOperand, GeneralEntityFactory.Create(rightOperand));
 }
Ejemplo n.º 15
0
 public ConflictResolution(IEntityFieldCore localField, IEntityFieldCore dbField)
 {
     LocalField     = localField;
     DBField        = dbField;
     UseYourChanges = Conflict;
 }