diff --git a/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs b/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs index 67be81e57..6cd423b43 100644 --- a/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs +++ b/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs @@ -88,7 +88,7 @@ internal static IEnumerable GetInternal(TDbConnection co var key = (long)type.GetHashCode(); // Note: For SqlConnection, the ConnectionString is changing if the (Integrated Security=False). Actually for this isolation, the database name is enough. - if (!string.IsNullOrWhiteSpace(connection?.Database)) + if (!string.IsNullOrWhiteSpace(connection.Database)) { key += connection.Database.GetHashCode(); } @@ -175,7 +175,7 @@ internal static async Task> GetAsyncInternal var key = (long)type.GetHashCode(); // Note: For SqlConnection, the ConnectionString is changing if the (Integrated Security=False). Actually for this isolation, the database name is enough. - if (!string.IsNullOrWhiteSpace(connection?.Database)) + if (!string.IsNullOrWhiteSpace(connection.Database)) { key += connection.Database.GetHashCode(); } diff --git a/RepoDb.Core/RepoDb/DataEntityDataReader.cs b/RepoDb.Core/RepoDb/DataEntityDataReader.cs index 2a9b61edd..e159e90ff 100644 --- a/RepoDb.Core/RepoDb/DataEntityDataReader.cs +++ b/RepoDb.Core/RepoDb/DataEntityDataReader.cs @@ -100,7 +100,7 @@ public DataEntityDataReader(string tableName, // Type var entityType = typeof(TEntity); EntityType = entityType == StaticType.Object ? - (entities?.FirstOrDefault()?.GetType() ?? entityType) : + (entities.FirstOrDefault()?.GetType() ?? entityType) : entityType; isDictionaryStringObject = EntityType.IsDictionaryStringObject(); diff --git a/RepoDb.Core/RepoDb/Extensions/DbCommandExtension.cs b/RepoDb.Core/RepoDb/Extensions/DbCommandExtension.cs index 4b56249a7..17e99bcf3 100644 --- a/RepoDb.Core/RepoDb/Extensions/DbCommandExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/DbCommandExtension.cs @@ -256,7 +256,7 @@ private static void CreateParametersInternal(IDbCommand command, if (propertiesToSkip != null) { classProperties = classProperties? - .Where(p => propertiesToSkip?.Contains(p.PropertyInfo.Name, + .Where(p => propertiesToSkip.Contains(p.PropertyInfo.Name, StringComparer.OrdinalIgnoreCase) == false); } @@ -401,7 +401,7 @@ internal static void CreateParameters(IDbCommand command, { return; } - CreateParameters(command, queryGroup?.GetFields(true), propertiesToSkip, entityType, dbFields); + CreateParameters(command, queryGroup.GetFields(true), propertiesToSkip, entityType, dbFields); } /// @@ -475,7 +475,7 @@ private static void CreateParameters(this IDbCommand command, // Variables var dbField = GetDbField(queryField.Field.Name, dbFields); var value = queryField.Parameter.Value; - var valueType = value?.GetType()?.GetUnderlyingType(); + var valueType = value?.GetType().GetUnderlyingType(); var isEnum = valueType?.IsEnum; // PropertyHandler @@ -492,14 +492,14 @@ private static void CreateParameters(this IDbCommand command, if (IsAutomaticConversion(dbField)) { var underlyingType = dbField.Type.GetUnderlyingType(); - value = AutomaticConvert(value, classProperty?.PropertyInfo?.PropertyType?.GetUnderlyingType(), underlyingType); + value = AutomaticConvert(value, classProperty?.PropertyInfo?.PropertyType.GetUnderlyingType(), underlyingType); valueType = underlyingType; } // DbType var dbType = (valueType != null ? clientTypeToDbTypeResolver.Resolve(valueType) : null) ?? classProperty?.GetDbType() ?? - value?.GetType()?.GetDbType(); + value?.GetType().GetDbType(); // Try get fallback dbType by classProperty to avoid being mistaken as string when value is null. if (dbType == null && classProperty != null) @@ -557,7 +557,7 @@ private static void CreateParametersForInOperation(this IDbCommand command, { var name = string.Concat(queryField.Parameter.Name, "_In_", i); var value = values[i]; - var valueType = value?.GetType()?.GetUnderlyingType(); + var valueType = value?.GetType().GetUnderlyingType(); var isEnum = valueType?.IsEnum; // Propertyhandler @@ -573,7 +573,7 @@ private static void CreateParametersForInOperation(this IDbCommand command, if (IsAutomaticConversion(dbField)) { var underlyingType = dbField.Type.GetUnderlyingType(); - value = AutomaticConvert(value, value?.GetType()?.GetUnderlyingType(), underlyingType); + value = AutomaticConvert(value, value?.GetType().GetUnderlyingType(), underlyingType); valueType = underlyingType; } @@ -613,8 +613,8 @@ private static void CreateParametersForBetweenOperation(this IDbCommand command, { var leftValue = values[0]; var rightValue = values[1]; - var leftValueType = leftValue?.GetType()?.GetUnderlyingType(); - var rightValueType = rightValue?.GetType()?.GetUnderlyingType(); + var leftValueType = leftValue?.GetType().GetUnderlyingType(); + var rightValueType = rightValue?.GetType().GetUnderlyingType(); var isLeftEnum = leftValueType?.IsEnum; var isRightEnum = rightValueType?.IsEnum; diff --git a/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs b/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs index db1f69349..dba2aa24f 100644 --- a/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs @@ -2051,7 +2051,7 @@ internal static Field GetAndGuardPrimaryKeyOrIdentityKey(Type entityType, else { // Properties - var properties = PropertyCache.Get(entityType) ?? entityType?.GetClassProperties(); + var properties = PropertyCache.Get(entityType) ?? entityType.GetClassProperties(); var property = (ClassProperty)null; // Primary @@ -2161,7 +2161,7 @@ internal static QueryGroup WhatToQueryGroup(this IDbConnection connection, var queryGroup = WhatToQueryGroup(what); if (queryGroup == null) { - var whatType = what?.GetType(); + var whatType = what.GetType(); if (whatType.IsClassType() || whatType.IsAnonymousType()) { var field = GetAndGuardPrimaryKeyOrIdentityKey(connection, tableName, transaction, whatType); @@ -2199,7 +2199,7 @@ internal static async Task WhatToQueryGroupAsync(this IDbConnecti var queryGroup = WhatToQueryGroup(what); if (queryGroup == null) { - var whatType = what?.GetType(); + var whatType = what.GetType(); if (whatType.IsClassType() || whatType.IsAnonymousType()) { var field = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, whatType, cancellationToken); @@ -2421,7 +2421,7 @@ internal static QueryGroup ToQueryGroup(DbField dbField, } if (dbField != null) { - var type = entity?.GetType(); + var type = entity.GetType(); if (type.IsClassType()) { var properties = PropertyCache.Get(type) ?? type.GetClassProperties(); @@ -2632,7 +2632,7 @@ internal static QueryGroup CreateQueryGroupForUpsert(IDictionary } } - if (queryFields?.Any() != true) + if (queryFields.Any() != true) { throw new MissingFieldsException("No qualifier fields defined for the 'Upsert' operation. Please check the items defined at the dictionary object."); } @@ -2837,7 +2837,7 @@ private static DbCommand CreateDbCommandForExecutionInternal(this IDbConnection // Func if (param != null) { - var func = FunctionCache.GetPlainTypeToDbParametersCompiledFunction(param?.GetType(), entityType, dbFields); + var func = FunctionCache.GetPlainTypeToDbParametersCompiledFunction(param.GetType(), entityType, dbFields); if (func != null) { var cmd = (DbCommand)command; diff --git a/RepoDb.Core/RepoDb/Extensions/ExpressionExtension.cs b/RepoDb.Core/RepoDb/Extensions/ExpressionExtension.cs index 9b2ee2275..1369f91f8 100644 --- a/RepoDb.Core/RepoDb/Extensions/ExpressionExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/ExpressionExtension.cs @@ -115,7 +115,7 @@ public static Field GetField(this MethodCallExpression expression) // Contains if (expression.Method.Name == "Contains") { - var last = expression.Arguments?.Last(); + var last = expression.Arguments.Last(); if (last?.IsMember() == true) { return last.ToMember().GetField(); @@ -198,7 +198,7 @@ public static string GetName(this MethodCallExpression expression) expression.Method.Name == "StartsWith" || expression.Method.Name == "EndsWith") { - var last = expression.Arguments?.Last(); + var last = expression.Arguments.Last(); if (last?.IsMember() == true) { return last.ToMember().Member.GetMappedName(); @@ -383,7 +383,7 @@ public static object GetValue(this UnaryExpression expression) => /// The instance of object where the value is to be extracted. /// The extracted value from object. public static object GetValue(this MethodCallExpression expression) => - expression.Method.GetValue(expression.Object?.GetValue(), expression.Arguments?.Select(argExpression => argExpression.GetValue()).ToArray()); + expression.Method.GetValue(expression.Object?.GetValue(), expression.Arguments.Select(argExpression => argExpression.GetValue()).ToArray()); /// /// Gets a value from the current instance of object. @@ -419,7 +419,7 @@ public static object GetValue(this ListInitExpression expression) var list = Activator.CreateInstance(expression.Type); foreach (var item in expression.Initializers) { - item.AddMethod.Invoke(list, new[] { item.Arguments?.FirstOrDefault().GetValue() }); + item.AddMethod.Invoke(list, new[] { item.Arguments.FirstOrDefault().GetValue() }); } return list; } diff --git a/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs b/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs index 50973434b..4b05e0868 100644 --- a/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/PropertyInfoExtension.cs @@ -33,7 +33,7 @@ public static T GetCustomAttribute(this PropertyInfo property) public static Attribute GetCustomAttribute(this PropertyInfo property, Type type) { - var attributes = property.GetCustomAttributes(type, false)?.WithType(); + var attributes = property.GetCustomAttributes(type, false).WithType(); return attributes?.FirstOrDefault(a => a.GetType() == type); } diff --git a/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs b/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs index 9c6b07ea4..06b5fab61 100644 --- a/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/TypeExtension.cs @@ -25,8 +25,8 @@ public static class TypeExtension /// The current type. /// The instance of with the most arguments. public static ConstructorInfo GetConstructorWithMostArguments(this Type type) => - type.GetConstructors()?.Where(item => item.GetParameters().Length > 0)? - .OrderByDescending(item => item.GetParameters().Length)?.FirstOrDefault(); + type.GetConstructors().Where(item => item.GetParameters().Length > 0) + .OrderByDescending(item => item.GetParameters().Length).FirstOrDefault(); /// /// Checks whether the current type is of type . @@ -162,7 +162,7 @@ public static Type MakeGenericTypeFrom(this Type currentType, Type sourceType) { var genericTypes = sourceType?.GetGenericArguments(); - if (genericTypes?.Length == currentType?.GetGenericArguments()?.Length) + if (genericTypes?.Length == currentType?.GetGenericArguments().Length) { return currentType.MakeGenericType(genericTypes); } @@ -201,7 +201,7 @@ internal static bool IsClassHandlerValidForModel(this Type classHandlerType, item.Name == StaticType.IClassHandler.Name && item.Namespace == StaticType.IClassHandler.Namespace); if (targetInterface != null) { - return targetInterface.GetGenericArguments()?.FirstOrDefault() == targetModelType; + return targetInterface.GetGenericArguments().FirstOrDefault() == targetModelType; } return false; } diff --git a/RepoDb.Core/RepoDb/Field.cs b/RepoDb.Core/RepoDb/Field.cs index e595e9989..5368fe62c 100644 --- a/RepoDb.Core/RepoDb/Field.cs +++ b/RepoDb.Core/RepoDb/Field.cs @@ -273,7 +273,7 @@ internal static IEnumerable Parse(NewExpression expression) .WithType(); var classProperties = PropertyCache.Get()? .Where(classProperty => - properties?.FirstOrDefault(property => string.Equals(property.Name, classProperty.PropertyInfo.Name, StringComparison.OrdinalIgnoreCase)) != null)? + properties?.FirstOrDefault(property => string.Equals(property.Name, classProperty.PropertyInfo.Name, StringComparison.OrdinalIgnoreCase)) != null) .Select(classProperty => classProperty.PropertyInfo); return (classProperties ?? properties).Select(property => property.AsField()); } diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs index 69a16c090..896cf52e3 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs @@ -720,7 +720,7 @@ internal static int DeleteAllInternal(this IDbConnection connection, { break; } - var field = new QueryField(key.Name.AsQuoted(dbSetting), Operation.In, keyValues?.AsList()); + var field = new QueryField(key.Name.AsQuoted(dbSetting), Operation.In, keyValues.AsList()); deletedRows += DeleteInternal(connection: connection, tableName: tableName, where: new QueryGroup(field), @@ -906,7 +906,7 @@ public static async Task DeleteAllAsyncInternal(this IDbConnection connecti { break; } - var field = new QueryField(key.Name.AsQuoted(dbSetting), Operation.In, keyValues?.AsList()); + var field = new QueryField(key.Name.AsQuoted(dbSetting), Operation.In, keyValues.AsList()); deletedRows += await DeleteAsyncInternal(connection: connection, tableName: tableName, where: new QueryGroup(field), diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs index d74212da5..b5cf07104 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs @@ -186,7 +186,7 @@ internal static TResult InsertInternal(this IDbConnection conn IStatementBuilder statementBuilder = null) where TEntity : class { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return InsertInternalBase, TResult>(connection: connection, tableName: tableName, @@ -398,7 +398,7 @@ internal static Task InsertAsyncInternal(this IDbConn CancellationToken cancellationToken = default) where TEntity : class { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return InsertAsyncInternalBase, TResult>(connection: connection, tableName: tableName, diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs index 9e791d401..75787b0c1 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs @@ -662,7 +662,7 @@ internal static TResult MergeInternal(this IDbConnection conne // Return the result if (setting.IsUseUpsert == false) { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return MergeInternalBase, TResult>(connection: connection, tableName: tableName, @@ -691,7 +691,7 @@ internal static TResult MergeInternal(this IDbConnection conne } else { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return UpsertInternalBase, TResult>(connection: connection, tableName: tableName, @@ -1416,7 +1416,7 @@ internal static Task MergeAsyncInternal(this IDbConne // Return the result if (setting.IsUseUpsert == false) { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return MergeAsyncInternalBase, TResult>(connection: connection, tableName: tableName, @@ -1447,7 +1447,7 @@ internal static Task MergeAsyncInternal(this IDbConne } else { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return UpsertAsyncInternalBase, TResult>(connection: connection, tableName: tableName, diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs index f3de03e20..29fe3df3a 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs @@ -579,7 +579,7 @@ internal static int UpdateInternal(this IDbConnection connection, IStatementBuilder statementBuilder = null) where TEntity : class { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return UpdateInternalBase>(connection: connection, tableName: tableName, @@ -1215,7 +1215,7 @@ internal static Task UpdateAsyncInternal(this IDbConnection connec CancellationToken cancellationToken = default) where TEntity : class { - if (entity?.GetType()?.IsDictionaryStringObject() == true) + if (entity?.GetType().IsDictionaryStringObject() == true) { return UpdateAsyncInternalBase>(connection: connection, tableName: tableName, diff --git a/RepoDb.Core/RepoDb/QueryField/ParseExpression.cs b/RepoDb.Core/RepoDb/QueryField/ParseExpression.cs index 2c8a7e741..637ad51fd 100644 --- a/RepoDb.Core/RepoDb/QueryField/ParseExpression.cs +++ b/RepoDb.Core/RepoDb/QueryField/ParseExpression.cs @@ -267,7 +267,7 @@ internal static QueryField ParseContains(MethodCallExpression expressio // Value if (expression?.Object != null) { - if (expression?.Object?.Type == StaticType.String) + if (expression.Object?.Type == StaticType.String) { var likeable = ConvertToLikeableValue("Contains", Converter.ToType(expression.Arguments.First().GetValue())); return ToLike(property.GetMappedName(), likeable, unaryNodeType); diff --git a/RepoDb.Core/RepoDb/QueryGroup/ParseDynamic.cs b/RepoDb.Core/RepoDb/QueryGroup/ParseDynamic.cs index f592f245e..1733ec240 100644 --- a/RepoDb.Core/RepoDb/QueryGroup/ParseDynamic.cs +++ b/RepoDb.Core/RepoDb/QueryGroup/ParseDynamic.cs @@ -56,7 +56,7 @@ public static QueryGroup Parse(T obj, } // Return - return queryFields?.Any() == true ? new QueryGroup(queryFields).Fix() : null; + return queryFields.Any() == true ? new QueryGroup(queryFields).Fix() : null; } } } diff --git a/RepoDb.Core/RepoDb/QueryGroup/ParseExpression.cs b/RepoDb.Core/RepoDb/QueryGroup/ParseExpression.cs index 66f7df21a..cd1bc435d 100644 --- a/RepoDb.Core/RepoDb/QueryGroup/ParseExpression.cs +++ b/RepoDb.Core/RepoDb/QueryGroup/ParseExpression.cs @@ -153,11 +153,11 @@ private static QueryGroup Parse(UnaryExpression expression) { var queryGroup = (QueryGroup)null; - if (expression.Operand?.IsMember() == true) + if (expression.Operand.IsMember() == true) { queryGroup = Parse(expression.Operand.ToMember(), expression.NodeType); } - else if (expression.Operand?.IsMethodCall() == true) + else if (expression.Operand.IsMethodCall() == true) { queryGroup = Parse(expression.Operand.ToMethodCall(), expression.NodeType); } diff --git a/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs b/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs index 2b56661c1..b738a43b3 100644 --- a/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs +++ b/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs @@ -147,7 +147,7 @@ internal static IEnumerable GetInputFieldDirections(IEnumerable< { return Enumerable.Empty(); } - return fields?.Select((value, index) => new FieldDirection + return fields.Select((value, index) => new FieldDirection { Index = index, DbField = value, @@ -166,7 +166,7 @@ internal static IEnumerable GetOutputFieldDirections(IEnumerable { return Enumerable.Empty(); } - return fields?.Select((value, index) => new FieldDirection + return fields.Select((value, index) => new FieldDirection { Index = index, DbField = value, @@ -285,7 +285,7 @@ internal static ParameterInfo GetPropertyHandlerGetParameter(object handlerInsta /// /// internal static ParameterInfo GetPropertyHandlerGetParameter(MethodInfo getMethod) => - getMethod?.GetParameters()?.First(); + getMethod?.GetParameters().First(); /// /// @@ -301,7 +301,7 @@ internal static ParameterInfo GetPropertyHandlerSetParameter(object handlerInsta /// /// internal static ParameterInfo GetPropertyHandlerSetParameter(MethodInfo setMethod) => - setMethod?.GetParameters()?.First(); + setMethod?.GetParameters().First(); /// /// @@ -1477,7 +1477,7 @@ internal static Expression GetDictionaryStringObjectPropertyValueExpression(Expr // Property Handler expression = ConvertExpressionToPropertyHandlerSetExpression(expression, null, - dbField?.Type.GetUnderlyingType()); + dbField.Type.GetUnderlyingType()); // Convert to object return ConvertExpressionToTypeExpression(expression, StaticType.Object); diff --git a/RepoDb.Core/RepoDb/Reflection/Compiler/DataProvider.cs b/RepoDb.Core/RepoDb/Reflection/Compiler/DataProvider.cs index e1ea1c75d..7e7d393d6 100644 --- a/RepoDb.Core/RepoDb/Reflection/Compiler/DataProvider.cs +++ b/RepoDb.Core/RepoDb/Reflection/Compiler/DataProvider.cs @@ -62,7 +62,7 @@ internal static Attribute GetSystemSqlServerTypeMapAttribute(ClassProperty prope { return property? .PropertyInfo - .GetCustomAttributes()? + .GetCustomAttributes() .FirstOrDefault(e => e.GetType().FullName.Equals("RepoDb.Attributes.SystemSqlServerTypeMapAttribute")); } @@ -146,7 +146,7 @@ internal static Attribute GetMicrosoftSqlServerTypeMapAttribute(ClassProperty pr { return property? .PropertyInfo - .GetCustomAttributes()? + .GetCustomAttributes() .FirstOrDefault(e => e.GetType().FullName.Equals("RepoDb.Attributes.MicrosoftSqlServerTypeMapAttribute")); } @@ -230,7 +230,7 @@ internal static Attribute GetMySqlDbTypeTypeMapAttribute(ClassProperty property) { return property? .PropertyInfo - .GetCustomAttributes()? + .GetCustomAttributes() .FirstOrDefault(e => e.GetType().FullName.Equals("RepoDb.Attributes.MySqlTypeMapAttribute")); } @@ -314,7 +314,7 @@ internal static Attribute GetNpgsqlDbTypeTypeMapAttribute(ClassProperty property { return property? .PropertyInfo - .GetCustomAttributes()? + .GetCustomAttributes() .FirstOrDefault(e => e.GetType().FullName.Equals("RepoDb.Attributes.NpgsqlTypeMapAttribute")); } diff --git a/RepoDb.Core/RepoDb/Resolvers/ClientTypeToAverageableClientTypeResolver.cs b/RepoDb.Core/RepoDb/Resolvers/ClientTypeToAverageableClientTypeResolver.cs index a84c68d1d..1dc2b5154 100644 --- a/RepoDb.Core/RepoDb/Resolvers/ClientTypeToAverageableClientTypeResolver.cs +++ b/RepoDb.Core/RepoDb/Resolvers/ClientTypeToAverageableClientTypeResolver.cs @@ -22,7 +22,7 @@ public Type Resolve(Type type) } // Get the type - type = type?.GetUnderlyingType(); + type = type.GetUnderlyingType(); // Only convert those numerics if (type == StaticType.Int16 || diff --git a/RepoDb.Core/RepoDb/Resolvers/ClientTypeToDbTypeResolver.cs b/RepoDb.Core/RepoDb/Resolvers/ClientTypeToDbTypeResolver.cs index f5770fb27..4dc1d35e4 100644 --- a/RepoDb.Core/RepoDb/Resolvers/ClientTypeToDbTypeResolver.cs +++ b/RepoDb.Core/RepoDb/Resolvers/ClientTypeToDbTypeResolver.cs @@ -27,7 +27,7 @@ public class ClientTypeToDbTypeResolver : IResolver throw new NullReferenceException("The type must not be null."); } - type = type?.GetUnderlyingType(); + type = type.GetUnderlyingType(); if (type == StaticType.Int64) { diff --git a/RepoDb.Core/RepoDb/StatementBuilders/BaseStatementBuilder.cs b/RepoDb.Core/RepoDb/StatementBuilders/BaseStatementBuilder.cs index c53e4a1f9..55c8058d8 100644 --- a/RepoDb.Core/RepoDb/StatementBuilders/BaseStatementBuilder.cs +++ b/RepoDb.Core/RepoDb/StatementBuilders/BaseStatementBuilder.cs @@ -731,12 +731,12 @@ public virtual string CreateQuery(QueryBuilder queryBuilder, if (orderBy != null) { // Check if the order fields are present in the given fields - var unmatchesOrderFields = orderBy?.Where(orderField => - fields?.FirstOrDefault(f => + var unmatchesOrderFields = orderBy.Where(orderField => + fields.FirstOrDefault(f => string.Equals(orderField.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesOrderFields?.Any() == true) + if (unmatchesOrderFields.Any() == true) { throw new MissingFieldsException($"The order fields '{unmatchesOrderFields.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); @@ -798,11 +798,11 @@ public virtual string CreateQueryAll(QueryBuilder queryBuilder, { // Check if the order fields are present in the given fields var unmatchesOrderFields = orderBy?.Where(orderField => - fields?.FirstOrDefault(f => + fields.FirstOrDefault(f => string.Equals(orderField.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesOrderFields?.Any() == true) + if (unmatchesOrderFields.Any() == true) { throw new MissingFieldsException($"The order fields '{unmatchesOrderFields.Select(field => field.AsField(DbSetting)).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); @@ -986,7 +986,7 @@ public virtual string CreateUpdate(QueryBuilder queryBuilder, !string.Equals(f.Name, identityField?.Name, StringComparison.OrdinalIgnoreCase)); // Check if there are updatable fields - if (updatableFields?.Any() != true) + if (updatableFields.Any() != true) { throw new EmptyException("The list of updatable fields cannot be null or empty."); } @@ -1052,12 +1052,12 @@ public virtual string CreateUpdateAll(QueryBuilder queryBuilder, if (qualifiers?.Any() == true) { // Check if the qualifiers are present in the given fields - var unmatchesQualifiers = qualifiers?.Where(field => + var unmatchesQualifiers = qualifiers.Where(field => fields?.FirstOrDefault(f => string.Equals(field.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesQualifiers?.Any() == true) + if (unmatchesQualifiers.Any() == true) { throw new InvalidQualifiersException($"The qualifiers '{unmatchesQualifiers.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); @@ -1068,7 +1068,7 @@ public virtual string CreateUpdateAll(QueryBuilder queryBuilder, if (primaryField != null) { // Make sure that primary is present in the list of fields before qualifying to become a qualifier - var isPresent = fields?.FirstOrDefault(f => + var isPresent = fields.FirstOrDefault(f => string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)) != null; // Throw if not present @@ -1095,7 +1095,7 @@ public virtual string CreateUpdateAll(QueryBuilder queryBuilder, qualifiers.FirstOrDefault(q => string.Equals(q.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Check if there are updatable fields - if (fields?.Any() != true) + if (fields.Any() != true) { throw new EmptyException("The list of updatable fields cannot be null or empty."); } diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkDelete.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkDelete.cs index a29bfd194..b31915ad8 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkDelete.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkDelete.cs @@ -108,7 +108,7 @@ public static partial class SqlConnectionExtension // Do the bulk insertion first using (var dataTable = CreateDataTableWithSingleColumn(primaryOrIdentityField, primaryKeys)) { - var options = primaryOrIdentityDbField?.IsIdentity == true ? + var options = primaryOrIdentityDbField.IsIdentity == true ? Compiler.GetEnumFunc("KeepIdentity")() : default; var mappings = new[] { new BulkInsertMapItem(primaryOrIdentityField.Name, primaryOrIdentityField.Name) }; @@ -281,7 +281,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields .Where(e => @@ -423,7 +423,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } @@ -692,7 +692,7 @@ public static partial class SqlConnectionExtension // Do the bulk insertion first using (var dataTable = CreateDataTableWithSingleColumn(primaryOrIdentityField, primaryKeys)) { - var options = primaryOrIdentityDbField?.IsIdentity == true ? + var options = primaryOrIdentityDbField.IsIdentity == true ? Compiler.GetEnumFunc("KeepIdentity")() : default; var mappings = new[] { new BulkInsertMapItem(primaryOrIdentityField.Name, primaryOrIdentityField.Name) }; @@ -868,7 +868,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields .Where(e => @@ -1013,7 +1013,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkInsert.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkInsert.cs index 46d4a8fe1..c9dcd5978 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkInsert.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkInsert.cs @@ -286,7 +286,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields? .Where(e => @@ -389,7 +389,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } @@ -631,9 +631,9 @@ public static partial class SqlConnectionExtension // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); - var entityType = entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity); + var entityType = entities.FirstOrDefault()?.GetType() ?? typeof(TEntity); var entityFields = entityType.IsDictionaryStringObject() ? - GetDictionaryStringObjectFields(entities?.FirstOrDefault() as IDictionary) : + GetDictionaryStringObjectFields(entities.FirstOrDefault() as IDictionary) : FieldCache.Get(entityType); var fields = dbFields?.Select(dbField => dbField.AsField()); @@ -835,7 +835,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields? .Where(e => @@ -941,7 +941,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkMerge.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkMerge.cs index 141ccfbbf..b42f51e77 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkMerge.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkMerge.cs @@ -94,9 +94,9 @@ public static partial class SqlConnectionExtension var dbFields = DbFieldCache.Get(connection, tableName, transaction, true); // Variables needed - var entityType = entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity); + var entityType = entities.FirstOrDefault()?.GetType() ?? typeof(TEntity); var entityFields = entityType.IsDictionaryStringObject() ? - GetDictionaryStringObjectFields(entities?.FirstOrDefault() as IDictionary) : + GetDictionaryStringObjectFields(entities.FirstOrDefault() as IDictionary) : FieldCache.Get(entityType); var fields = dbFields?.Select(dbField => dbField.AsField()); var primaryDbField = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary); @@ -350,7 +350,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields .Where(e => @@ -494,7 +494,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } @@ -770,9 +770,9 @@ public static partial class SqlConnectionExtension var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed - var entityType = entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity); + var entityType = entities.FirstOrDefault()?.GetType() ?? typeof(TEntity); var entityFields = entityType.IsDictionaryStringObject() ? - GetDictionaryStringObjectFields(entities?.FirstOrDefault() as IDictionary) : + GetDictionaryStringObjectFields(entities.FirstOrDefault() as IDictionary) : FieldCache.Get(entityType); var fields = dbFields?.Select(dbField => dbField.AsField()); var primaryDbField = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary); @@ -1029,7 +1029,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields .Where(e => @@ -1176,7 +1176,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkUpdate.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkUpdate.cs index 2317338c8..259d831fb 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkUpdate.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Base/BulkUpdate.cs @@ -121,7 +121,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields .Where(e => @@ -257,7 +257,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } @@ -538,7 +538,7 @@ public static partial class SqlConnectionExtension else { // Filter the fields (based on the data reader) - if (readerFields?.Any() == true) + if (readerFields.Any() == true) { fields = fields .Where(e => @@ -680,7 +680,7 @@ public static partial class SqlConnectionExtension where TSqlTransaction : DbTransaction { // Validate - if (dataTable?.Rows?.Count <= 0) + if (dataTable?.Rows.Count <= 0) { return default; } diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/SqlConnectionExtension.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/SqlConnectionExtension.cs index 097bbe396..ef6cb1981 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/SqlConnectionExtension.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/SqlConnectionExtension.cs @@ -675,7 +675,7 @@ private static string GetBulkMergeSqlText(string tableName, // QUALIFIERS .On() .OpenParen() - .WriteText(qualifiers? + .WriteText(qualifiers .Select( field => field.AsJoinQualifier("S", "T", dbSetting)) .Join(" AND ")) diff --git a/RepoDb.MySql/RepoDb.MySql/StatementBuilders/MySqlStatementBuilder.cs b/RepoDb.MySql/RepoDb.MySql/StatementBuilders/MySqlStatementBuilder.cs index d6cc284b8..e4e88cfdc 100644 --- a/RepoDb.MySql/RepoDb.MySql/StatementBuilders/MySqlStatementBuilder.cs +++ b/RepoDb.MySql/RepoDb.MySql/StatementBuilders/MySqlStatementBuilder.cs @@ -72,7 +72,7 @@ public override string CreateBatchQuery(QueryBuilder queryBuilder, } // Validate order by - if (orderBy == null || orderBy?.Any() != true) + if (orderBy == null || orderBy.Any() != true) { throw new EmptyException("The argument 'orderBy' is required."); } @@ -403,8 +403,8 @@ public override string CreateMerge(QueryBuilder queryBuilder, // Check the qualifiers if (qualifiers?.Any() == true) { - var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField?.Name, StringComparison.OrdinalIgnoreCase)); - if (others?.Any() == true) + var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)); + if (others.Any() == true) { throw new InvalidQualifiersException($"MySql is using the primary key as qualifier for merge operation. " + $"Consider creating 'PrimaryKey' in the {tableName} and set the 'qualifiers' to NULL."); @@ -506,8 +506,8 @@ public override string CreateMergeAll(QueryBuilder queryBuilder, // Check the qualifiers if (qualifiers?.Any() == true) { - var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField?.Name, StringComparison.OrdinalIgnoreCase)); - if (others?.Any() == true) + var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)); + if (others.Any() == true) { throw new InvalidQualifiersException($"MySql is using the primary key as qualifier for merge operation. " + $"Consider creating 'PrimaryKey' in the {tableName} and set the 'qualifiers' to NULL."); @@ -667,12 +667,12 @@ public override string CreateQuery(QueryBuilder queryBuilder, if (orderBy != null) { // Check if the order fields are present in the given fields - var unmatchesOrderFields = orderBy?.Where(orderField => - fields?.FirstOrDefault(f => + var unmatchesOrderFields = orderBy.Where(orderField => + fields.FirstOrDefault(f => string.Equals(orderField.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesOrderFields?.Any() == true) + if (unmatchesOrderFields.Any() == true) { throw new MissingFieldsException($"The order fields '{unmatchesOrderFields.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); diff --git a/RepoDb.MySqlConnector/RepoDb.MySqlConnector/StatementBuilders/MySqlConnectorStatementBuilder.cs b/RepoDb.MySqlConnector/RepoDb.MySqlConnector/StatementBuilders/MySqlConnectorStatementBuilder.cs index da1d5ec9e..33489624b 100644 --- a/RepoDb.MySqlConnector/RepoDb.MySqlConnector/StatementBuilders/MySqlConnectorStatementBuilder.cs +++ b/RepoDb.MySqlConnector/RepoDb.MySqlConnector/StatementBuilders/MySqlConnectorStatementBuilder.cs @@ -72,7 +72,7 @@ public override string CreateBatchQuery(QueryBuilder queryBuilder, } // Validate order by - if (orderBy == null || orderBy?.Any() != true) + if (orderBy == null || orderBy.Any() != true) { throw new EmptyException("The argument 'orderBy' is required."); } @@ -403,8 +403,8 @@ public override string CreateMerge(QueryBuilder queryBuilder, // Check the qualifiers if (qualifiers?.Any() == true) { - var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField?.Name, StringComparison.OrdinalIgnoreCase)); - if (others?.Any() == true) + var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)); + if (others.Any() == true) { throw new InvalidQualifiersException($"MySql is using the primary key as qualifier for merge operation. " + $"Consider creating 'PrimaryKey' in the {tableName} and set the 'qualifiers' to NULL."); @@ -506,8 +506,8 @@ public override string CreateMergeAll(QueryBuilder queryBuilder, // Check the qualifiers if (qualifiers?.Any() == true) { - var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField?.Name, StringComparison.OrdinalIgnoreCase)); - if (others?.Any() == true) + var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)); + if (others.Any() == true) { throw new InvalidQualifiersException($"MySql is using the primary key as qualifier for merge operation. " + $"Consider creating 'PrimaryKey' in the {tableName} and set the 'qualifiers' to NULL."); @@ -667,12 +667,12 @@ public override string CreateQuery(QueryBuilder queryBuilder, if (orderBy != null) { // Check if the order fields are present in the given fields - var unmatchesOrderFields = orderBy?.Where(orderField => - fields?.FirstOrDefault(f => + var unmatchesOrderFields = orderBy.Where(orderField => + fields.FirstOrDefault(f => string.Equals(orderField.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesOrderFields?.Any() == true) + if (unmatchesOrderFields.Any() == true) { throw new MissingFieldsException($"The order fields '{unmatchesOrderFields.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); diff --git a/RepoDb.PostgreSql/RepoDb.PostgreSql/StatementBuilders/PostgreSqlStatementBuilder.cs b/RepoDb.PostgreSql/RepoDb.PostgreSql/StatementBuilders/PostgreSqlStatementBuilder.cs index a924e46d2..0052f4bd3 100644 --- a/RepoDb.PostgreSql/RepoDb.PostgreSql/StatementBuilders/PostgreSqlStatementBuilder.cs +++ b/RepoDb.PostgreSql/RepoDb.PostgreSql/StatementBuilders/PostgreSqlStatementBuilder.cs @@ -73,7 +73,7 @@ public override string CreateBatchQuery(QueryBuilder queryBuilder, } // Validate order by - if (orderBy == null || orderBy?.Any() != true) + if (orderBy == null || orderBy.Any() != true) { throw new EmptyException("The argument 'orderBy' is required."); } @@ -333,8 +333,8 @@ public override string CreateMerge(QueryBuilder queryBuilder, // Check the qualifiers if (qualifiers?.Any() == true) { - var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField?.Name, StringComparison.OrdinalIgnoreCase)); - if (others?.Any() == true) + var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)); + if (others.Any() == true) { throw new InvalidQualifiersException($"PostgreSql is using the primary key as qualifier for (INSERT or REPLACE) operation. " + $"Consider creating 'PrimaryKey' in the {tableName} and set the 'qualifiers' to NULL."); @@ -463,8 +463,8 @@ public override string CreateMergeAll(QueryBuilder queryBuilder, // Check the qualifiers if (qualifiers?.Any() == true) { - var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField?.Name, StringComparison.OrdinalIgnoreCase)); - if (others?.Any() == true) + var others = qualifiers.Where(f => !string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)); + if (others.Any() == true) { throw new InvalidQualifiersException($"PostgreSql is using the primary key as qualifier for (INSERT or REPLACE) operation. " + $"Consider creating 'PrimaryKey' in the {tableName} and set the 'qualifiers' to NULL."); @@ -594,12 +594,12 @@ public override string CreateQuery(QueryBuilder queryBuilder, if (orderBy != null) { // Check if the order fields are present in the given fields - var unmatchesOrderFields = orderBy?.Where(orderField => - fields?.FirstOrDefault(f => + var unmatchesOrderFields = orderBy.Where(orderField => + fields.FirstOrDefault(f => string.Equals(orderField.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesOrderFields?.Any() == true) + if (unmatchesOrderFields.Any() == true) { throw new MissingFieldsException($"The order fields '{unmatchesOrderFields.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); diff --git a/RepoDb.SqLite/RepoDb.SqLite/StatementBuilders/SqLiteStatementBuilder.cs b/RepoDb.SqLite/RepoDb.SqLite/StatementBuilders/SqLiteStatementBuilder.cs index 776fff935..5b5486b50 100644 --- a/RepoDb.SqLite/RepoDb.SqLite/StatementBuilders/SqLiteStatementBuilder.cs +++ b/RepoDb.SqLite/RepoDb.SqLite/StatementBuilders/SqLiteStatementBuilder.cs @@ -63,7 +63,7 @@ public override string CreateBatchQuery(QueryBuilder queryBuilder, } // Validate order by - if (orderBy == null || orderBy?.Any() != true) + if (orderBy == null || orderBy.Any() != true) { throw new EmptyException("The argument 'orderBy' is required."); } @@ -544,12 +544,12 @@ public override string CreateQuery(QueryBuilder queryBuilder, if (orderBy != null) { // Check if the order fields are present in the given fields - var unmatchesOrderFields = orderBy?.Where(orderField => - fields?.FirstOrDefault(f => + var unmatchesOrderFields = orderBy.Where(orderField => + fields.FirstOrDefault(f => string.Equals(orderField.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesOrderFields?.Any() == true) + if (unmatchesOrderFields.Any() == true) { throw new MissingFieldsException($"The order fields '{unmatchesOrderFields.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); diff --git a/RepoDb.SqlServer/RepoDb.SqlServer/StatementBuilders/SqlServerStatementBuilder.cs b/RepoDb.SqlServer/RepoDb.SqlServer/StatementBuilders/SqlServerStatementBuilder.cs index 9492f0755..be5a35f0c 100644 --- a/RepoDb.SqlServer/RepoDb.SqlServer/StatementBuilders/SqlServerStatementBuilder.cs +++ b/RepoDb.SqlServer/RepoDb.SqlServer/StatementBuilders/SqlServerStatementBuilder.cs @@ -73,7 +73,7 @@ public override string CreateBatchQuery(QueryBuilder queryBuilder, } // Validate order by - if (orderBy == null || orderBy?.Any() != true) + if (orderBy == null || orderBy.Any() != true) { throw new EmptyException("The argument 'orderBy' is required."); } @@ -380,7 +380,7 @@ public override string CreateMerge(QueryBuilder queryBuilder, string.Equals(field.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesQualifiers?.Any() == true) + if (unmatchesQualifiers.Any() == true) { throw new InvalidQualifiersException($"The qualifiers '{unmatchesQualifiers.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); @@ -391,7 +391,7 @@ public override string CreateMerge(QueryBuilder queryBuilder, if (primaryField != null) { // Make sure that primary is present in the list of fields before qualifying to become a qualifier - var isPresent = fields?.FirstOrDefault(f => string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)) != null; + var isPresent = fields.FirstOrDefault(f => string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)) != null; // Throw if not present if (isPresent == false) @@ -537,7 +537,7 @@ public override string CreateMergeAll(QueryBuilder queryBuilder, string.Equals(field.Name, f.Name, StringComparison.OrdinalIgnoreCase)) == null); // Throw an error we found any unmatches - if (unmatchesQualifiers?.Any() == true) + if (unmatchesQualifiers.Any() == true) { throw new InvalidQualifiersException($"The qualifiers '{unmatchesQualifiers.Select(field => field.Name).Join(", ")}' are not " + $"present at the given fields '{fields.Select(field => field.Name).Join(", ")}'."); @@ -548,7 +548,7 @@ public override string CreateMergeAll(QueryBuilder queryBuilder, if (primaryField != null) { // Make sure that primary is present in the list of fields before qualifying to become a qualifier - var isPresent = fields?.FirstOrDefault(f => string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)) != null; + var isPresent = fields.FirstOrDefault(f => string.Equals(f.Name, primaryField.Name, StringComparison.OrdinalIgnoreCase)) != null; // Throw if not present if (isPresent == false)