示例#1
0
        static void Main(string[] args)
        {
            MapperProvider.Instance.RegisterAssembly(Assembly.GetExecutingAssembly());

            // allows us to create ADO.NET classes
            // without knowing the actual driver
            // and by just using the app/web.config
            var factory = new AppConfigConnectionFactory("DemoDb");
            var connection = factory.Create();

            var queries = new UserQueries(connection);

            var constraints = new QueryConstraints<User>()
                .SortBy(x => x.FirstName)
                .Page(2, 2);
            var result = queries.FindAll(constraints);
            foreach (var user in result.Items)
            {
                // Note that each user is not mapped until it's requested
                // as opposed to the entire collection being mapped first.
                Console.WriteLine(user.FirstName);
            }

            // and storage:
            var storage = new UserStorage(connection);
            var firstUser = storage.Load(1);
            Console.WriteLine(firstUser.FirstName);
        }