public void SetMappingConvention(IMappingConvention mappingConvention) { if (mappingConvention == null) { throw new ArgumentNullException("mappingConvention"); } if (this.log.IsInfo) { this.log.Info(LogMessages.ConfigureExtensions_UsingMappingConvention, mappingConvention.GetType().FullName); } ObjectInfo.MappingConvention = mappingConvention; }
public void SetMappingConvention(IMappingConvention mappingConvention) { if (mappingConvention == null) { throw new ArgumentNullException("mappingConvention"); } if (this.log.IsInfo) { this.log.Info(LogMessages.ConfigureExtensions_UsingMappingConvention, mappingConvention.GetType().FullName); } ObjectInfo.MappingConvention = mappingConvention; }
Query(IMappingConvention convention) { var allPropertyNames = Properties.Select(p => convention.ToDb(p.Name)).ToArray(); var insertPropertyNames = Properties.Except(DbGenerated).Select(p => p.Name).ToArray(); var keyPropertyNames = KeyProperties.Select(p => p.Name).ToArray(); var nonKeyProperties = Properties.Except(KeyProperties).ToArray(); var nonKeyPropertyNames = nonKeyProperties.Select(p => p.Name).ToArray(); Func <string, string> assign = s => $"{convention.ToDb(s)} = {convention.Parameter(s)}"; var insertColumns = string.Join(", ", insertPropertyNames.Select(convention.ToDb)); var insertValues = string.Join(", ", insertPropertyNames.Select(s => $"{convention.Parameter(s)}")); var whereClause = string.Join(" AND ", keyPropertyNames.Select(assign)); var updateColumns = string.Join(", ", nonKeyPropertyNames.Select(assign)); var allColumns = string.Join(", ", allPropertyNames); var tableName = convention.ToDb(typeof(T).Name); Insert = $"INSERT INTO {tableName} ({insertColumns}) VALUES ({insertValues})"; Delete = $"DELETE FROM {tableName} WHERE {whereClause}"; Update = $"UPDATE {tableName} SET {updateColumns} WHERE {whereClause}"; Select = $"SELECT {allColumns} FROM {tableName} WHERE {whereClause}"; SelectAll = $"SELECT {allColumns} FROM {tableName}"; Count = $"SELECT COUNT(*) FROM {tableName}"; }
/// <summary> /// Initializes a new instance of the <see cref="MappingConventionAdapter"/> class. /// </summary> /// <param name="mappingConvention">The mapping convention to encapsulate.</param> public MappingConventionAdapter(IMappingConvention mappingConvention) { _mappingConvention = mappingConvention; }
internal DbConfig(Action<IDbCommand> prepareCommand, IMappingConvention convention, string providerName) { PrepareCommand = prepareCommand; MappingConvention = convention; ProviderName = providerName; }
// ReSharper restore StaticMemberInGenericType internal static IQuery Create(IMappingConvention convention) => new Query <T>(convention);
public DbConfig(Action <IDbCommand> prepareCommand, IMappingConvention convention, string providerName) { PrepareCommand = prepareCommand; MappingConvention = convention; ProviderName = providerName; }
/// <summary> /// Resets the object info state, removing any cached object information and restoring the default mapping convention. /// </summary> /// <remarks> /// Makes it easier to unit test using different mapping conventions - should remain an internal method. /// </remarks> internal static void Reset() { mappingConvention = null; objectInfos = GetObjectInfos(); }