@param array       $data
@param Entity|null $entity

@return $this|Record
971737
public static function create($data = [], Entity $entity = null)
    {
        $record = new static($data, $entity);

        $record->save();

        return $record;
    }
721320
protected function updateByEntity($data, $entity)
	{
		return $this->aggregate[$entity->getType(true)]->update($data, $entity);
	}
1241729
protected function populate($entity, array $entityData)
    {
        foreach ($entityData as $key => $value) {
            if ($this->propertyAccessor->isWritable($entity, $key)) {
                $this->propertyAccessor->setValue($entity, $key, $value);
            }
        }

        return $entity;
    }
118236
public function setData(array $data)
    {
        $data = $this->setIdFromData($data);

        parent::setData($data);
        return $this;
    }
1062012
public function populate($data)
    {
        if (is_null($data)) {
            return $this;
        }

        $data = $this->normalizeData($data);

        $fromDb = false;
        if ($this->isDbData($data)) {
            $fromDb = true;
        } else {
            unset($data['id']);
            unset($data['_id']);
        }

        $validation = $this->arr();

        /* @var $entityAttribute AbstractAttribute */
        foreach ($this->attributes as $attributeName => $entityAttribute) {
            if (!$entityAttribute->getAfterPopulate()) {
                $this->populateAttribute($attributeName, $entityAttribute, $validation, $data, $fromDb);
            }
        }

        foreach ($this->attributes as $attributeName => $entityAttribute) {
            if ($entityAttribute->getAfterPopulate()) {
                $this->populateAttribute($attributeName, $entityAttribute, $validation, $data, $fromDb);
            }
        }

        if ($validation->count() > 0) {
            $attributes = [];
            foreach ($validation as $attr => $error) {
                foreach ($error as $key => $value) {
                    $attributes[$key] = $value;
                }
            }
            $ex = new EntityException(EntityException::VALIDATION_FAILED, [get_class($this), $validation->count()]);
            $ex->setInvalidAttributes($attributes);
            throw $ex;
        }

        return $this;
    }
937877
public function insert(Entity $entity = null, Repository $repository = null)
    {
        $entity = $this->getEntityIfEmpty($entity);
        $repository = $entity->getRepositoryIfEmpty($repository);

        $this->trigger(['saving', 'inserting']);

        $insert = $repository->insert($this, $entity);

        $this->trigger(['inserted', 'saved']);

        $this->setOriginalFromData();

        return $insert;
    }
227306
protected static function exeCreate(string $entity, array $data, bool $save)
    {
        $dicionario = new Dicionario($entity);
        $dicionario->setData($data);

        if ($save)
            $dicionario->save();

        return self::return($dicionario);
    }
220949
public function materialize(array $data, $entity)
    {
        //use a entity proxy to delay loading the related entity
        if ($this->_cardinality == 1) {
            $config = array();
            $config['relationship'] = $this;
            $config['value'] = $entity;
            $config['property'] = $this->_child_key;
            $config['service_identifier'] = $this->getChildRepository()->getDescription()->getEntityIdentifier();

            return new AnDomainEntityProxy(new AnConfig($config));
        } else {
            return $this->getSet($entity);
        }
    }
1255791
public function load(EntityInterface $entity)
    {
        $adapter = $this->getAdapter();
        $relTable = $this->getParentTableName();
        $pmk = $this->getEntityDescriptor()->getPrimaryKey();
        $fnk = $this->getForeignKey();

        $data = Sql::createSql($adapter)
            ->select($relTable)
            ->where([
                "{$relTable}.{$fnk} = :id" => [
                    ':id' => $entity->{$pmk->name}
                ]
            ])
            ->first();

        $relEntity = $this->getParentEntityMapper()->createFrom($data);

        return null == $relEntity ? null :$this->registerEntity($relEntity);
    }
1228204
protected static function exeRead(string $entity, $data = null)
    {
        if (!is_array($data) && !is_numeric($data))
            return null;

        if (is_array($data)) {
            $read = new TableCrud($entity);
            $read->loadArray($data);
            if ($read->exist())
                $data = (int)$read->getDados()['id'];

            if (empty($data) || !is_numeric($data))
                return null;
        }

        return self::readValues($entity, $data);
    }
592089
public static function fill(array $data, COCEntity &$entity)
    {
        $vars = get_object_vars($entity);
        foreach ($vars as $var => $_) {
            if (array_key_exists($var, $data)) {
                $entity->{$var} = $data[$var];
            }
        }
    }
66072
public static function add(string $entity, array $data, bool $save = true)
    {
        return self::exeCreate($entity, $data, $save);
    }
644428
private function createEntity(array $key, array $data)
    {
        list($partitonKey, $rowKey) = array_values($key);

        $entity = new Entity();
        $entity->setPartitionKey((string) $partitonKey);
        $entity->setRowKey((string) $rowKey);

        foreach ($data as $variable => $value) {
            $type = $this->getPropertyType($value);
            $entity->addProperty($variable, $type, $value);
        }

        return $entity;
    }
875259
public function removeEntity(Entity $entity)
    {
        foreach ($this->entities as $key => $entityElement) {
            if ($entityElement === $entity) {
                unset($this->entities[$key]);
                break;
            }
        }

        return $this;
    }
18860
public function registerManaged($entity, array $id, array $data)
    {
        $isProxy = $entity instanceof GhostObjectInterface && ! $entity->isProxyInitialized();
        $oid     = spl_object_id($entity);

        $this->entityIdentifiers[$oid]  = $id;
        $this->entityStates[$oid]       = self::STATE_MANAGED;
        $this->originalEntityData[$oid] = $data;

        $this->addToIdentityMap($entity);

        if ($entity instanceof NotifyPropertyChanged && ! $isProxy) {
            $entity->addPropertyChangedListener($this);
        }
    }
121489
public static function fromData(array $data)
    {
        $class = get_called_class();
        $isDynamic = is_a($class, DynamicEntity::class, true);

        /** @var static $entity */
        $entity = (new \ReflectionClass($class))->newInstanceWithoutConstructor();

        object_set_properties($entity, $data, $isDynamic);

        if (method_exists($entity, '__construct')) {
            $entity->__construct();
        }

        $entity->markNew(false);

        return $entity;
    }
174779
public function load(Entity $entity)
    {
        $data = $entity->getRawData();
        if (!is_array($data) || !isset($data[$this->getForeignKey()])) {
            return null;
        }
        /** @var Select $sql */
        $sql = call_user_func_array(
            [$this->getRelatedEntity(), 'find'],
            []
        );
        $pmk = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getPrimaryKey();
        $table = Entity\Manager::getInstance()->get($this->getRelatedEntity())
            ->getEntity()->getTableName();
        $sql-> where(
            [
                "{$table}.{$pmk} = :id" => [
                    ':id' => $data[$this->getForeignKey()]
                ]
            ]
        );
        return $sql->first();
    }