示例#1
0
        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);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
 public abstract Task UpdateBaseTypeEntityAsync(IPersistenceEntity entity, IContext ctx = default);
示例#3
0
 public override async Task UpdateBaseTypeEntityAsync(IPersistenceEntity entity, IContext ctx = default)
 => await UpdateAsync(entity : (TEntity)entity, ctx : ctx).ConfigureAwait(false);
示例#4
0
 public abstract Task InsertBaseTypeEntityAsync(IPersistenceEntity entity, bool newReferenceKeyAssignmentAllowed = default, IContext ctx = default);
示例#5
0
 public override async Task InsertBaseTypeEntityAsync(IPersistenceEntity entity, bool newReferenceKeyAssignmentAllowed = default, IContext ctx = default)
 => await InsertAsync(entity : (TEntity)entity, newReferenceKeyAssignmentAllowed : newReferenceKeyAssignmentAllowed, ctx : ctx).ConfigureAwait(false);