public async Task <bool> InsertAsync <TEntity>(TEntity entity) where TEntity : Entity, new() { var properties = typeof(TEntity).GetReadWriteProperties(); var values = new Dictionary <string, object>(properties.Length); var query = new QueryBuilder <TEntity>(connectorQuery, properties); for (var i = 0; i < properties.Length; i++) { if (properties[i].PropertyType.IsArray) { var arr = (query.PropertyGetter[i](entity) as Array); var arrElementType = arr.GetType().GetElementType(); for (var j = 0; j <= arr.Length; j++) { values.Add(properties[i].GetName() + j, arr.GetValue(j).ChangeTypeGet(arrElementType)); } } else if (!properties[i].HasAttribute <AutoIncrementAttribute>()) { values.Add(properties[i].GetName(), query.PropertyGetter[i](entity)); } } return(await ExecuteAsync(query.BuildInsert(values))); }
public ValueTask <bool> InsertAsync <TEntity>(TEntity entity) where TEntity : Entity, new() { var properties = typeof(TEntity).GetReadWriteProperties(); var values = new Dictionary <string, (object ColumnValue, bool IsArrayGroup)>(properties.Length); var builder = new QueryBuilder <TEntity>(Connector.Query, properties); for (var i = 0; i < properties.Length; i++) { if (properties[i].PropertyType.IsArray && properties[i].HasAttribute <GroupAttribute>()) { var arr = (builder.PropertyGetter[i](entity) as Array); var arrElementType = arr.GetType().GetElementType(); for (var j = 0; j < arr.Length; j++) { values.Add(properties[i].GetName() + j, (arr.GetValue(j).ChangeTypeGet(arrElementType), true)); } } else if (!properties[i].HasAttribute <AutoIncrementAttribute>()) { values.Add(properties[i].GetName(), (builder.PropertyGetter[i](entity), false)); } } builder.BuildInsert(values); return(ExecuteAsync(builder)); }