示例#1
0
        public void Insert(TEntity entity)
        {
            var adapter        = new EntityAdapter <TEntity>(entity, _map);
            var hasIdentityKey = _map.Key.KeyType == PrimaryKeyType.Integer &&
                                 _map.Key.KeyGeneration == PrimaryKeyGeneration.Server;
            var keyColumnName = _map.Key.GetColumnName();

            if (_map.Key.KeyType == PrimaryKeyType.Guid &&
                _map.Key.KeyGeneration == PrimaryKeyGeneration.Client)
            {
                adapter.Key = GuidComb.Create();
            }

            var values = adapter.GetValues().Where(x => !hasIdentityKey ||
                                                   (x.Key != keyColumnName)).ToDictionary(x => x.Key, x => x.Value);

            var insert = new Insert {
                HasIdentityKey = hasIdentityKey,
                Type           = Model.Insert.SetType.Values,
                Into           = new Table {
                    Name = _table
                },
                Values = values
            };

            var command = Command.Create(InsertWriter <TEntity>
                                         .CreateStatement(insert, _map), _profiler);

            if (command.Statement.Result == Statement.ResultType.None)
            {
                command.ExecuteNonQuery(_connectionManager);
            }
            else
            {
                adapter.Key = command.ExecuteScalar(_connectionManager);
            }
        }
示例#2
0
 public void Should_generate_guid()
 {
     GuidComb.Create().ShouldNotEqual(Guid.Empty);
 }