public List <SqlScript> Update <TMain>(eInsertUpdateType type = eInsertUpdateType.Normal, params TMain[] units) where TMain : class, iTable, new() { if (type != eInsertUpdateType.Normal) { return(Create(type, units)); } return(Update <TMain>(units)); }
public List <SqlScript> Create <TMain>(eInsertUpdateType type = eInsertUpdateType.Normal, params TMain[] units) where TMain : class, iTable, new() { List <SqlScript> sqls = new List <SqlScript>(); foreach (var item in units) { sqls.AddRange(item.InsertScript(paramchar, randomidcharacter, type)); } return(sqls); }
/// <summary> /// Insert Data /// </summary> /// <param name="obj"></param> /// <param name="paramchar"></param> /// <param name="randomidcharacter"></param> /// <returns></returns> public static List <SqlScript> InsertScript(this iTable obj, string paramchar, string randomidcharacter, eInsertUpdateType inserttype = eInsertUpdateType.Normal) { Type type = obj.GetType(); SqlScript sqlscript = new SqlScript(); string into = ""; string value = ""; insertsql(type, paramchar, randomidcharacter, obj, ref into, ref value, ref sqlscript.dbparameters); string insert = "INSERT"; switch (inserttype) { case eInsertUpdateType.Normal: break; case eInsertUpdateType.Replace: insert += " OR REPLACE "; break; case eInsertUpdateType.Ignore: insert += " OR IGNORE "; break; default: break; } if (type.Name.IndexOf('`') > 0) { sqlscript.sql = $"{insert} INTO { type.Name.Remove(type.Name.IndexOf('`'))} ({into}) VALUES ({value})"; } else { sqlscript.sql = $"{insert} INTO {type.Name.Replace("`1", "")} ({into}) VALUES ({value})"; } // sqlscript.sql = $"INSERT INTO {type.Name.Replace("`1", "")} ({into}) VALUES ({value})"; // sqlscript.sql = $"INSERT INTO { type.Name.Remove(type.Name.IndexOf('`'))} ({into}) VALUES ({value})"; return(new List <SqlScript>() { sqlscript }); }