public object GetEntities(object Entity, List <string> propertiesToUseInFilter = null)
        {
            var Statement = DMLStatementFactory.GetDMLStatementForGenericEntity(_tenant, Entity, DMLStatemtType.SelectAll, propertiesToUseInFilter);

            this.SqlStatementExecuted(Statement.PreparedStatement, Statement.Variables);
            return(((IExecuteDML)_dbaccess).Execute(Statement));
        }
        public void CreateEntityStorageMechanism(object Entity)
        {
            var Statement = DMLStatementFactory.GetDDLStatementGenericEntityStorageCreation(_tenant, Entity);

            ((IExecuteDML)_dbaccess).Execute(Statement);

            //this.sqlStatementExecuted(Statement.PreparedStatement);

            SqlStatementExecuted?.Invoke(Statement.PreparedStatement, Statement.Variables);
        }
        public void CreateEntity(object Entity)
        {
            var Statement = DMLStatementFactory.GetDMLStatementForGenericEntity(_tenant, Entity, DMLStatemtType.Insert, null);

            ((IExecuteDML)_dbaccess).Execute(Statement);

            //this.sqlStatementExecuted(Statement.PreparedStatement);


            SqlStatementExecuted?.Invoke(Statement.PreparedStatement, Statement.Variables);
        }
        public long UpdateEntity(object Entity)
        {
            EntityDescriber ed = new EntityDescriber(Entity);

            if (ed.UniqueKeyProvidedOnEntity() == false && ed.PrimaryKeyProvidedOnEntity() == false)
            {
                throw new Exception("Neither a Primary Key nor UniqueKey was provided for the object.");
            }

            var Statement = DMLStatementFactory.GetDMLStatementForGenericEntity(_tenant, Entity, DMLStatemtType.Update, null);
            var ret       = (Int32)((IExecuteDML)_dbaccess).Execute(Statement);

            SqlStatementExecuted?.Invoke(Statement.PreparedStatement, Statement.Variables);
            return(ret);
        }
        public bool DoesEntityWithSamePrimaryKeyExist(object Entity)
        {
            EntityDescriber ed = new EntityDescriber(Entity);

            if (ed.PrimaryKeys().Count > 0)
            {
                var sql = DMLStatementFactory.BuildExistenceCheckSql(Entity, true);
                List <ISQLDMLStatementVariable> vars = DMLStatementFactory.GetUniqueKeyNameValuePairs(Entity, true, false);
                SQLDMLStatement dml = new SQLDMLStatement
                {
                    PreparedStatement = sql,
                    StatemtType       = DMLStatemtType.Select,
                    Variables         = vars
                };

                var results = (DataTable)((IExecuteDML)_dbaccess).Execute(dml);
                var count   = Convert.ToInt32(results.Rows[0].ItemArray[0]);
                return(count > 0);
            }
            else
            {
                return(false);
            }
        }