Exemplo n.º 1
0
        public void show_unit_of_work()
        {
            // theStore is a DocumentStore
            using (var session = theStore.OpenSession())
            {
                // All I'm doing here is recording references
                // to all the ADO.Net commands executed by
                // this session
                var logger = new RecordingLogger();
                session.Logger = logger;

                // Insert some new documents
                session.Store(new User {
                    UserName = "******", FirstName = "Luke", LastName = "Skywalker"
                });
                session.Store(new User {
                    UserName = "******", FirstName = "Leia", LastName = "Organa"
                });
                session.Store(new User {
                    UserName = "******", FirstName = "Wedge", LastName = "Antilles"
                });


                // Delete all users matching a certain criteria
                session.DeleteWhere <User>(x => x.UserName == "hansolo");

                // deleting a single document by Id, if you had one
                session.Delete <User>(Guid.NewGuid());

                // Persist in a single transaction
                session.SaveChanges();

                // All of this was done in one batched command
                // in the same transaction
                logger.Commands.Count.ShouldBe(1);

                // I'm just writing out the Sql executed here
                var sql       = logger.Commands.Single().CommandText;
                var directory = Path.Combine(AppContext.BaseDirectory, "bin", "unitofwork.sql");

                new FileSystem()
                .WriteStringToFile(directory, sql);
            }
        }
Exemplo n.º 2
0
        public void show_unit_of_work()
        {
            
            
// theStore is a DocumentStore
using (var session = theStore.OpenSession())
{
    // All I'm doing here is recording references
    // to all the ADO.Net commands executed by
    // this session
    var logger = new RecordingLogger();
    session.Logger = logger;

    // Insert some new documents
    session.Store(new User {UserName = "******", FirstName = "Luke", LastName = "Skywalker"});
    session.Store(new User {UserName = "******", FirstName = "Leia", LastName = "Organa"});
    session.Store(new User {UserName = "******", FirstName = "Wedge", LastName = "Antilles"});


    // Delete all users matching a certain criteria
    session.DeleteWhere<User>(x => x.UserName == "hansolo");

    // deleting a single document by Id, if you had one
    session.Delete<User>(Guid.NewGuid());

    // Persist in a single transaction
    session.SaveChanges();

    // All of this was done in one batched command
    // in the same transaction
    logger.Commands.Count.ShouldBe(1);

    // I'm just writing out the Sql executed here
    var sql = logger.Commands.Single().CommandText;
    new FileSystem()
        .WriteStringToFile(@"bin\unitofwork.sql", sql);

}
        }