public bool Delete(Expression <Func <T, bool> > expression)
        {
            Expression x    = expression.Body;
            var        h    = x.ToString().Split(new char[] { '=' });
            var        name = h[0].TrimStart(new char[] { '(', 'x', '.' });
            var        tt   = h[2].Replace('"', ' ').TrimEnd(new char[] { ')' });

            var t  = x.ToString();
            var xx = t.TrimStart(new char[] { '(', 'x', '.' }).TrimEnd(new char[] { ')' });

            var           sx      = xx.Replace("==", "=").Replace('"', ' ').ToString();
            var           Name    = typeof(T).Name;
            StringBuilder builder = new StringBuilder();

            builder.Append($"DELETE  {Name} WHERE {name}=@{name}");
            string     query   = builder.ToString();
            SqlCommand command = new SqlCommand(query, Connected.Connection);

            command.CommandType = System.Data.CommandType.Text;
            command.Parameters.AddWithValue($"@{name}", tt);

            Commond.ExecuteQuery(command);

            return(false);
        }
Beispiel #2
0
        public bool QueryInserter(T entity)
        {
            ProcedureQuery.Insert(entity);
            SqlCommand comm = new SqlCommand(entity.GetType().Name + "_Insert", Connected.Connection);

            comm.CommandType = CommandType.StoredProcedure;
            foreach (var item in entity.GetType().GetProperties())
            {
                if (Tools.FindID(item))
                {
                    continue;
                }
                if (Tools.IsNull(item.GetValue(entity)))
                {
                    comm.Parameters.AddWithValue("@" + item.Name, item.GetValue(entity));
                }
            }
            return(Commond.ExecuteQuery(comm));
        }
        public static bool QueryDelete(dynamic entity, int id)
        {
            string Name = string.Empty;

            Procedures.DeleteProcedure(entity);
            SqlCommand command = new SqlCommand(entity.GetType().Name + "_Delete", Services.Connection);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            foreach (var item in entity.GetType().GetProperties())
            {
                if (Tools.FindID(item))
                {
                    Name = "@" + item.Name;
                    command.Parameters.AddWithValue(Name, id);
                }
            }

            return(Commond.ExecuteQuery(command));
        }
        public static bool QueryInserter(dynamic entity)
        {
            Procedures.InsertProcedure(entity);
            SqlCommand command = new SqlCommand(entity.GetType().Name + "_Insert", Services.Connection);

            command.CommandType = System.Data.CommandType.StoredProcedure;

            foreach (var item in entity.GetType().GetProperties())
            {
                if (Tools.FindID(item))
                {
                    continue;
                }
                if (Tools.IsNull(item.GetValue(entity)))
                {
                    command.Parameters.AddWithValue("@" + item.Name, item.GetValue(entity));
                }
            }
            return(Commond.ExecuteQuery(command));
        }