/// <summary> /// This is used to get a newly created db object and get its new ID. /// </summary> public IEnumerable <T> GetByEverythingExceptId(T item) { var filter = PropertyInfoFilterProvider.GetExcludeNotInDatabasePropertiesFilter(); // Shouldn't contain ID, since it is null var propertyInformation = GetPropertiesInformation(item, filter); //if (!propertyInformation.Any()) // return new List<T>(); var propertyNames = propertyInformation.Select(p => p.ColumnName).ToList(); var propertyValues = propertyInformation.Select(p => p.Value).ToList(); if (propertyNames.Count != propertyValues.Count) { throw new InvalidPropertyInformationException( $"The count of {nameof(propertyNames)}({propertyNames.Count}) " + $"doesn't match the count of {nameof(propertyValues)}({propertyValues.Count})."); } var constraints = GetAllConstraintsExceptId(propertyNames, propertyValues); var joinedConstraints = constraints.JoinToStrings(" "); var query = $"SELECT * FROM {tableName} WHERE {joinedConstraints}"; var result = queryExecutor.ExecuteQueryWitMultipleResults <T>(query); return(result); }
protected virtual (string joinedPropertyNames, string joinedPropertyValues) GetJoinedInsertInformation(T item) { var filter = PropertyInfoFilterProvider.GetExcludeNotInDatabasePropertiesFilter(); var propertyInformation = GetPropertiesInformation(item, filter).OrderBy(p => p.ColumnName).ToList(); var propertyNames = propertyInformation.Select(p => p.ColumnName); var propertyValues = propertyInformation.Select(p => p.Value); var joinedPropertyNames = propertyNames.JoinToStrings(); var joinedPropertyValues = propertyValues.JoinToStrings(surroundWith: ((char)34).ToString()); return(joinedPropertyNames, joinedPropertyValues); }