private void SetPersistenceEntity(IPersistenceEntity persistenceEntity) { var props = GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance); foreach (var prop in props) { var column = prop.GetCustomAttribute <Column>(); if (column != null) { string name = column.Name ?? prop.Name; if (name == GetNamePrimaryKey()) { continue; } object value = prop.GetValue(this); if (prop.PropertyType == typeof(string)) { if (value is null) { if (column.StringNotNullable) { throw new Exception($"String nullable in property column: '{prop.Name}'."); } persistenceEntity.AddColumn(name, DBNull.Value); } else { if (column.StringMaxLenght > 0) { int maxLenghtString = value.ToString().Length; if (maxLenghtString > column.StringMaxLenght) { throw new Exception($"String max capacity lenght in property column: '{prop.Name}'."); } } persistenceEntity.AddColumn(name, value); } } else { if (value is null) { persistenceEntity.AddColumn(name, DBNull.Value); } else { if (value.GetType() == typeof(bool)) { persistenceEntity.AddColumn(name, Convert.ToBoolean(value) ? 'S' : 'N'); } else { persistenceEntity.AddColumn(name, value); } } } } } }
public abstract Task UpdateBaseTypeEntityAsync(IPersistenceEntity entity, IContext ctx = default);
public override async Task UpdateBaseTypeEntityAsync(IPersistenceEntity entity, IContext ctx = default) => await UpdateAsync(entity : (TEntity)entity, ctx : ctx).ConfigureAwait(false);
public abstract Task InsertBaseTypeEntityAsync(IPersistenceEntity entity, bool newReferenceKeyAssignmentAllowed = default, IContext ctx = default);
public override async Task InsertBaseTypeEntityAsync(IPersistenceEntity entity, bool newReferenceKeyAssignmentAllowed = default, IContext ctx = default) => await InsertAsync(entity : (TEntity)entity, newReferenceKeyAssignmentAllowed : newReferenceKeyAssignmentAllowed, ctx : ctx).ConfigureAwait(false);