Is there a standard approach to generating sql dynamically?

后端 未结 8 2345
滥情空心
滥情空心 2021-02-20 00:17

I want to ask how other programmers are producing Dynamic SQL strings for execution as the CommandText of a SQLCommand object.

I am producing parameterized queries conta

8条回答
  •  甜味超标
    2021-02-20 00:45

    Usually it's something like this:

    string query= "SELECT {0} FROM .... WHERE {1}"
    StringBuilder selectclause = new StringBuilder();
    StringBuilder wherecaluse = new StringBuilder();
    
    // .... the logic here will vary greatly depending on what your system looks like
    
    MySqlcommand.CommandText = String.Format(query, selectclause.ToString(), whereclause.ToString());
    

    I'm also just getting started out with ORMs. You might want to take a look at one of those. ActiveRecord / Hibernate are some good keywords to google.

提交回复
热议问题