public static InsertStatementTemplate For(Type type, string table) { var key = new TypeAndTable(type, table); if (!Statements.ContainsKey(key)) { Statements[key] = new InsertStatementTemplate(key); } return(Statements[key]); }
private InsertStatementTemplate(TypeAndTable typeAndTable) { _typeAndTable = typeAndTable; _properties = typeAndTable.Type.GetProperties() .Where(p => p.GetCustomAttribute <GeneratedByDbAttribute>() == null) .ToArray(); var columns = string.Join(", ", _properties.Select(p => p.Name.InBrackets())); var parameterNames = string.Join(", ", _properties.Select(p => p.Name.ToParameterName())); CommandText = string.Format("insert into [{0}] ({1}) values ({2})", typeAndTable.Table, columns, parameterNames); }
protected bool Equals(TypeAndTable other) { return(other != null && other.Type == Type && other.Table == Table); }