Beispiel #1
0
        /// <summary>
        /// Gets the property values.
        /// </summary>
        /// <param name="obj">The obj.</param>
        /// <param name="columnNames">The column names.</param>
        /// <returns>The values.</returns>
        public static object[] GetPropertyValues(object obj, params string[] columnNames)
        {
            Check.Require(obj != null, "obj could not be null.");
            Check.Require(obj is DynEntity, "obj must be an DynEntity.");
            Check.Require(columnNames != null, "columnNames could not be null.");
            Check.Require(columnNames.Length > 0, "columnNames's length could not be 0.");

            DynEntity entityObj = obj as DynEntity;

            string[]      names    = entityObj.GetPropertyMappingColumnNames();
            object[]      values   = entityObj.GetPropertyValues();
            List <object> lsValues = new List <object>();

            foreach (string item in columnNames)
            {
                for (int i = 0; i < names.Length; i++)
                {
                    if (names[i] == item)
                    {
                        lsValues.Add(values[i]);
                        break;
                    }
                }
            }

            return(lsValues.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// Queries a single entity instance.
        /// </summary>
        /// <param name="returnEntityType">Type of the return entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="baseEntity">The base entity.</param>
        /// <returns>The query result.</returns>
        protected object QueryOne(DynEntity returnEntityType, string propertyName, DynEntity baseEntity)
        {
            Array objs = (Array)Query(returnEntityType, propertyName, baseEntity);

            if (objs != null && objs.Length > 0)
            {
                return(objs.GetValue(0));
            }
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Convert an entity array to a data table.
        /// </summary>
        /// <param name="objs">The entity array.</param>
        /// <returns>The data table.</returns>
        public static DataTable EntityArrayToDataTable(DynEntityType entityType, DynEntity[] objs)
        {
            EntityConfiguration ec;

            if (objs != null && objs.Length > 0)
            {
                ec = MetaDataManager.GetEntityConfiguration(objs[0].EntityType.FullName);
            }
            else
            {
                ec = MetaDataManager.GetEntityConfiguration(entityType.FullName);
            }

            DataTable table = new DataTable(ec.Name);

            foreach (PropertyConfiguration pc in ec.Properties)
            {
                if ((!pc.IsQueryProperty) || (pc.QueryType == "FkReverseQuery"))
                {
                    DataColumn column = new DataColumn(pc.QueryType == "FkReverseQuery" ? pc.MappingName : pc.Name, Util.GetType(pc.PropertyMappingColumnType.Replace("System.Nullable`1[", "").Replace("]", "")));
                    table.Columns.Add(column);
                }
            }

            if (objs != null && objs.Length > 0)
            {
                for (int i = 0; i < objs.Length; i++)
                {
                    object[] values = DynEntity.GetPropertyValues(objs[i], DynEntity.GetPropertyMappingColumnNames(MetaDataManager.GetEntityConfiguration(objs[0].EntityType.Name)));
                    DataRow  row    = table.NewRow();

                    int j = 0;
                    foreach (PropertyConfiguration pc in ec.Properties)
                    {
                        if ((!pc.IsQueryProperty) || (pc.QueryType == "FkReverseQuery"))
                        {
                            object value = (values[j] == null ? DBNull.Value : values[j]);
                            //if (pc.IsCompoundUnit)
                            //{
                            //    value = SerializationManager.Serialize(value);
                            //}
                            row[j] = value;
                        }

                        j++;
                    }

                    table.Rows.Add(row);
                }
            }
            table.AcceptChanges();
            return(table);
        }
Beispiel #4
0
 private void Entity_PropertyChanged(DynEntity sender, DynEntity.PropertyChangedEventArgs args)
 {
     if (sender == this && sender.isAttached)
     {
         //if ((args.OldValue == null && args.NewValue != null) || (args.OldValue != null && (!args.OldValue.Equals(args.NewValue))))
         //{
         lock (changedProperties)
         {
             changedProperties[args.PropertyName] = args.NewValue;
         }
         //}
     }
 }
        /// <summary>
        /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </summary>
        /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
        /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.</exception>
        public void Add(DynEntity item)
        {
            Check.Require(item != null, "item could not be null.");

            if (!list.Contains(item))
            {
                if (OnAddCallbackHandler != null)
                {
                    OnAddCallbackHandler(propertyName, item);
                }
                list.Add(item);
            }
        }
        /// <summary>
        /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </summary>
        /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
        /// <returns>
        /// true if item was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false. This method also returns false if item is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"></see>.
        /// </returns>
        /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.</exception>
        public bool Remove(DynEntity item)
        {
            if (list.Contains(item))
            {
                if (OnRemoveCallbackHandler != null)
                {
                    OnRemoveCallbackHandler(propertyName, item);
                }

                return(list.Remove(item));
            }
            else
            {
                return(false);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Queries array of the specified return entity type.
        /// </summary>
        /// <param name="returnEntityType">Type of the return entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="baseEntity">The base entity.</param>
        /// <returns>The query result.</returns>
        protected DynEntity[] Query(DynEntity returnEntityType, string propertyName, DynEntity baseEntity)
        {
            if (onQuery != null)
            {
                EntityConfiguration   ec = MetaDataManager.GetEntityConfiguration(baseEntity.EntityType.FullName);
                PropertyConfiguration pc = ec.GetPropertyConfiguration(propertyName);

                try
                {
                    return(onQuery(returnEntityType, propertyName, pc.QueryWhere, pc.QueryOrderBy, baseEntity));
                }
                catch (Exception ex)
                {
                    onQuery = null;
                    throw ex;
                }
            }
            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Data table to entity array.
        /// </summary>
        /// <param name="dt">The dt.</param>
        /// <param name="setEntitiesAsModified">if set to <c>true</c> set entities as modified.</param>
        /// <returns></returns>
        public static DynEntity[] DataTableToEntityArray(DynEntityType entityType, DataTable dt, bool setEntitiesAsModified)
        {
            if (dt == null)
            {
                return(null);
            }

            DynEntity[] objs = new DynEntity[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                objs[i] = new DynEntity(entityType);
                objs[i].SetPropertyValues(dt.Rows[i]);
                if (setEntitiesAsModified)
                {
                    objs[i].Attach();
                    objs[i].SetAllPropertiesAsModified();
                }
            }

            return(objs);
        }
Beispiel #9
0
        /// <summary>
        /// Gets the create property values.
        /// </summary>
        /// <param name="entityType">The type.</param>
        /// <param name="obj">The obj.</param>
        /// <returns>The values.</returns>
        public static object[] GetCreatePropertyValues(DynEntityType entityType, DynEntity obj)
        {
            Check.Require(obj != null, "obj could not be null.");

            return(GetPropertyValues(obj, GetCreatePropertyMappingColumnNames(entityType)));
        }
Beispiel #10
0
        /// <summary>
        /// Gets the primary DEFAULT_KEY values.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="obj">The obj.</param>
        /// <returns>The values.</returns>
        public static object[] GetPrimaryKeyValues(DynEntity obj)
        {
            Check.Require(obj != null, "obj could not be null.");

            return(GetPropertyValues(obj, GetPrimaryKeyMappingColumnNames(MetaDataManager.GetEntityConfiguration(((DynEntity)obj).EntityType.FullName))));
        }
 /// <summary>
 /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"></see> contains a specific value.
 /// </summary>
 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
 /// <returns>
 /// true if item is found in the <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false.
 /// </returns>
 public bool Contains(DynEntity item)
 {
     return(list.Contains(item));
 }