Exemplo n.º 1
0
        protected virtual void SetUpdatedAt(SeederExtension instance, IEnumerable <object> datas)
        {
            foreach (var data in datas)
            {
                var model = Convert.ChangeType(data, instance.GetModelType());

                var updatedatProperty = model.GetType().GetProperty("UpdatedAt"
                                                                    , BindingFlags.Public | BindingFlags.Instance);
                if (updatedatProperty != null && updatedatProperty.CanWrite)
                {
                    updatedatProperty.SetValue(model, DateTime.Now, null);
                }
            }
        }
Exemplo n.º 2
0
        protected virtual void SetId(SeederExtension instance, IEnumerable <object> datas, ModelBuilder modelBuilder)
        {
            var id = 1;

            foreach (var data in datas)
            {
                var model = Convert.ChangeType(data, instance.GetModelType());

                var idProperty = model.GetType().GetProperty("Id"
                                                             , BindingFlags.Public | BindingFlags.Instance);
                if (idProperty != null && idProperty.CanWrite)
                {
                    idProperty.SetValue(model, id++, null);
                }
            }

            IncreaseAutoIncrement(instance, modelBuilder, id);
        }
Exemplo n.º 3
0
 protected virtual void IncreaseAutoIncrement(SeederExtension instance, ModelBuilder modelBuilder, int lastId)
 {
     modelBuilder.Entity(instance.GetModelType()).Property("Id").HasIdentityOptions(lastId);
 }
Exemplo n.º 4
0
 protected virtual void InsertData(SeederExtension instance, IEnumerable <object> datas,
                                   ModelBuilder modelBuilder)
 {
     modelBuilder.Entity(instance.GetModelType()).HasData(datas);
 }