Background:
In the process of project development, it is often necessary to modify the SQL statement according to the value of the entity, for example, there is a student class Stu, the code is as follows:
1 Public classStudent2 {3 Public intID {Get;Set; }4 Public stringName {Get;Set; }5 Public intGrade {Get;Set; }6 Public stringNick {Get;Set; }7 Public stringCity {Get;Set; }8}View Code
Add a student record to the data table, sometimes, can only get some student information, such as: Do not know the student SHARPL grade information, the code is as follows:
1 New Student (); 2 " Sharp " ; 3 " Beijing ";
The Grade field value will take the default value of C # shaping data, then Stu. Grade is actually equal to 0, the information added to the database is not ideal, and the grade should be null when the student grade attribute value is unclear.
How to dynamically generate SQL statements based on entities