Ejemplo n.º 1
0
        /// <summary>
        /// Gets all entities that have Added, Modified and Deleted state.
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public ObjectCollection <T> GetChanges()
        {
            // We need to return all items that have been changed, including the delted rows
            ObjectCollection <T> changedItems = new ObjectCollection <T>();

            changedItems.BeginEdit();
            foreach (T item in this.Items)
            {
                // return any item that has been changed
                if (item.EntityState != EntityState.Unchanged)
                {
                    changedItems.Add(item);
                }
            }
            // Get the deleted items
            foreach (T item in _deletedEntities)
            {
                changedItems.Add(item);
            }
            changedItems.EndEdit();
            // return all the changed items (deleted, modified, added)
            return(changedItems);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all entities that have the specific state.
        /// </summary>
        /// <param name="state">The state of entities that you want to get.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public ObjectCollection <T> GetChanges(EntityState state)
        {
            ObjectCollection <T> changedItems = new ObjectCollection <T>();

            if (state == EntityState.Deleted)
            {
                foreach (T item in _deletedEntities)
                {
                    changedItems.Add(item);
                }
            }
            else
            {
                foreach (T item in this.Items)
                {
                    if (item.EntityState == state)
                    {
                        changedItems.Add(item);
                    }
                }
            }
            return(changedItems);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a list of data
        /// </summary>
        /// <param name="selectCommand"></param>

        public ObjectCollection <T> LoadListOfData <T>(SqlCommand selectCommand) where T : BaseEntity
        {
            SqlDataReader        reader      = null;
            ObjectCollection <T> objectsList = new ObjectCollection <T>();

            objectsList.BeginEdit();
            Type entityType = typeof(T);

            ConnectionStatus status = ConnectionStatus.Unknow;

            try
            {
                //Open connection
                status = BeginLoadData(selectCommand);

                //Begin load Data
                reader = selectCommand.ExecuteReader();
                int columnsCount = reader.FieldCount;

                while (reader.Read())
                {
                    // ConstructorInfo constructor = entityType.GetConstructor(new Type[] { });
                    T entity = Activator.CreateInstance(typeof(T)) as T;
                    entity.BeginEdit();
                    for (int i = 0; i < columnsCount; i++)
                    {
                        string propName = reader.GetName(i);
                        object value    = reader[propName];
                        if (value != DBNull.Value)
                        {
                            entity.SetValue(propName, value);
                            //if (reader.GetDataTypeName(reader.GetOrdinal(propName)).ToLower().Equals("image"))
                            //{
                            //    byte[] bytes = value as byte[];

                            //    MemoryStream stream = new MemoryStream(bytes);
                            //    Image image = Bitmap.FromStream(stream);
                            //    entity.SetValue(propName, image);
                            //}
                            //else
                            //{
                            //    entity.SetValue(propName, value);
                            //}
                        }
                        else
                        {
                            entity.SetValue(propName, null);
                        }
                    }
                    entity.EndEdit();
                    objectsList.Add(entity);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                EndLoadData(status);
                try
                {
                    reader.Close();
                }
                catch (Exception) { }
            }
            objectsList.EndEdit();
            objectsList.AcceptChanges();
            return(objectsList);
        }