Example #1
0
        private void Add <T>(T entity)
        {
            var hasIdentityId = ConventionReader.HasIdentityId(typeof(T));

            if (hasIdentityId)
            {
                var idProperty = ConventionReader.TryGetIdProperty(typeof(T));
                idProperty.SetValue(entity, ++_lastIdentityId, null);
            }

            AddRow(entity);
        }
Example #2
0
        public void Insert <T>(IEnumerable <T> entities)
        {
            var entityList = entities.ToList();

            if (_conventionReader.HasIdentityId(typeof(T)))
            {
                var commands = CreateIdentityInsertCommands(entities);

                var ids = _dbCommandExecutor.ExecuteScalarList <int>(commands, ConnectionString);

                for (int i = 0; i < ids.Count; i++)
                {
                    _conventionReader.SetId(entityList[i], ids[i]);
                }
            }
            else
            {
                var commands = CreateInsertCommands(entities);

                _dbCommandExecutor.ExecuteNonQuery(commands, ConnectionString);
            }
        }