Fix multiple where conditions and nullable fields on models
This commit is contained in:
parent
81c32f1137
commit
3c682780a4
@ -36,7 +36,18 @@ namespace ChaosBot.Attribute
|
||||
foreach (PropertyInfo prop in type.GetProperties())
|
||||
{
|
||||
string columnName = prop.Name;
|
||||
string columnType = DBEntity.DataTypes.GetValueOrDefault(prop.PropertyType).ToString();
|
||||
string columnType = null;
|
||||
if (prop.PropertyType.IsGenericType &&
|
||||
prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
|
||||
{
|
||||
Type[] typeArguments = prop.PropertyType.GetGenericArguments();
|
||||
if (typeArguments.Length == 1)
|
||||
columnType = DBEntity.DataTypes.GetValueOrDefault(typeArguments[0]).ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
columnType = DBEntity.DataTypes.GetValueOrDefault(prop.PropertyType).ToString();
|
||||
}
|
||||
StringBuilder constraintNameBuilder = new StringBuilder($"{table}_{columnName}");
|
||||
List<string> constraintsList = new List<string>();
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using ChaosBot.Attribute;
|
||||
|
||||
@ -10,7 +11,7 @@ namespace ChaosBot.Database.Entity
|
||||
[DBAutoIncrement]
|
||||
[DBNotNull]
|
||||
[DBUnique]
|
||||
public int id { get; private set; }
|
||||
public Nullable<int> id { get; private set; }
|
||||
public int points { get; private set; }
|
||||
public long userId { get; private set; }
|
||||
public long guildId { get; private set; }
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using ChaosBot.Attribute;
|
||||
|
||||
@ -10,7 +11,7 @@ namespace ChaosBot.Database.Entity
|
||||
[DBAutoIncrement]
|
||||
[DBNotNull]
|
||||
[DBUnique]
|
||||
public int id { get; private set; }
|
||||
public Nullable<int> id { get; private set; }
|
||||
public long userId { get; private set; }
|
||||
public long guildId { get; private set; }
|
||||
|
||||
|
||||
@ -117,13 +117,14 @@ namespace ChaosBot.Database
|
||||
public QueryBuilderRaw Where(Dictionary<string, FilterValue> whereCondition)
|
||||
{
|
||||
Append("WHERE");
|
||||
List<string> whereConditionList = new List<string>();
|
||||
foreach (string key in whereCondition.Keys)
|
||||
{
|
||||
FilterValue value = whereCondition.GetValueOrDefault(key);
|
||||
string parameterName = AddParameterAndReturnKey(key, value.Value);
|
||||
Append($"{key} {value.Comparison ?? "="} {parameterName}");
|
||||
whereConditionList.Add($"{key} {value.Comparison ?? "="} {parameterName}");
|
||||
}
|
||||
|
||||
Append(string.Join(" AND ", whereConditionList));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@ -157,7 +157,8 @@ namespace ChaosBot.Discord.Modules
|
||||
private void PickRaffle(StringBuilder sb)
|
||||
{
|
||||
Raffle winner = RaffleRepository.PickRandom(Convert.ToInt64(Context.Guild.Id));
|
||||
RaffleRepository.Delete(winner.id);
|
||||
if (winner.id != null)
|
||||
RaffleRepository.Delete((int)winner.id);
|
||||
sb.Append($"<@{winner.userId}> has won the raffle!");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user