/// <summary> Gets by identifier statement. </summary> /// <param name="type"> The type. </param> /// <returns> The by identifier statement. </returns> public virtual string GetByKeyStatement(Type type) { var key = SqlCache.TypeKeyPropertiesCache(type).Single(); return ($"SELECT {RenderPropertyList(SqlCache.TypePropertiesChache(type).ToArray())} FROM {RenderTableName(type)} WHERE {RenderPropertyName(key)} = {RenderParameterProperty(key)}"); }
/// <summary> Gets delete statememt. </summary> /// <param name="type"> The type. </param> /// <returns> The delete statememt. </returns> public virtual string GetDeleteStatememt(Type type) { var key = SqlCache.TypeKeyPropertiesCache(type).Single(); return ($"DELETE FROM {RenderTableName(type)} WHERE {RenderPropertyName(key)} = {RenderParameterProperty(key)}"); }
/// <summary> Gets insert automatic key statement. </summary> /// <param name="type"> The type. </param> /// <returns> The insert automatic key statement. </returns> public virtual string GetInsertAutoKeyStatement(Type type) { var key = SqlCache.TypeKeyPropertiesCache(type).Single(); var columnList = RenderAutoKeyColumnList(type).ToString(); var parameterList = RenderAutoKeyParameterList(type).ToString(); return ($"INSERT INTO {RenderTableName(type)} ({columnList}) VALUES ({parameterList}){GetAutoKeyStatement(key)}"); }
/// <summary> Gets update statement. </summary> /// <param name="type"> The type. </param> /// <returns> The update statement. </returns> public virtual string GetUpdateStatement(Type type) { var key = SqlCache.TypeKeyPropertiesCache(type).Single(); var setClauses = RenderSetStatements(type).ToString(); return ($"UPDATE {RenderTableName(type)} " + $"SET {setClauses} " + $"WHERE {RenderPropertyName(key)} = {RenderParameterProperty(key)}"); }
/// <summary> Gets key parameter. </summary> /// <param name="type"> The type. </param> /// <returns> The key parameter. </returns> public virtual string GetKeyParameter(Type type) { var key = SqlCache.TypeKeyPropertiesCache(type).Single(); return(RenderParameterProperty(key)); }
/// <summary> Gets the columns without keys in this collection. </summary> /// <param name="type"> The type. </param> /// <returns> /// An enumerator that allows foreach to be used to process the columns without keys in this /// collection. /// </returns> public virtual IEnumerable <PropertyInfo> GetPropertiesWithoutKey(Type type) { return(SqlCache.TypePropertiesChache(type).Except(new[] { SqlCache.TypeKeyPropertiesCache(type).Single() })); }