Example #1
0
        void FindingBeansWithSql(BeanApi api)
        {
            /// ## Finding Beans with SQL
            /// LimeBean doesn't introduce any custom query language, nor does it implement a LINQ provider.
            /// To find beans matching a criteria, use fragments of plain SQL:
            ///
            {
#if CODE
                var list = api.Find("book", "WHERE rating > 7");
#endif
            }
            /// Instead of embedding values into SQL code, it is recommended to use **parameters**:
            {
#if CODE
                var list = api.Find("book", "WHERE rating > {0}", 7);
#endif
            }
            /// Usage of parameters looks similar to `String.Format`, but instead of direct interpolation,
            /// they are transformed into fair ADO.NET command parameters to protect your queries from SQL-injection attacks.
            ///
            {
#if CODE
                var list = api.Find(
                    "book",
                    "WHERE release_date BETWEEN {0} and {1} AND author LIKE {2}",
                    new DateTime(1930, 1, 1), new DateTime(1950, 1, 1), "%remarque%"
                    );
#endif
            }
            ///
            /// You can use any SQL as long as the result maps to a set of beans.
            /// For other cases, see [Generic Queries](#generic-sql-queries).
            ///
            /// To find a single bean:
#if CODE
            var best = api.FindOne("book", "ORDER BY rating DESC LIMIT 1");
#endif
            /// To find out the number of beans without loading them:
#if CODE
            var count = api.Count("book", "WHERE rating > {0}", 7);
#endif
            /// It is also possible to perform unbuffered (memory-optimized) load for processing in a `foreach` loop.
            ///
            /// Data is 'Lazy Loaded' on each iteration using [C-sharp's IEnumerable Yield](http://programmers.stackexchange.com/a/97350)
#if CODE
            foreach (var bean in api.FindIterator("book", "ORDER BY rating"))
            {
                // do something with bean
            }
#endif
        }
Example #2
0
 void FindingBeansWithSql(BeanApi api)
 {
     /// ## Finding Beans with SQL
     /// LimeBean doesn't introduce any custom query language, nor does it implement a LINQ provider.
     /// To find beans matching a criteria, use snippets of plain SQL:
     ///
     {
     #if CODE
         var list = api.Find("book", "WHERE rating > 7");
     #endif
     }
     /// Instead of embedding values into SQL code, it is recommended to use **parameters**:
     {
     #if CODE
         var list = api.Find("book", "WHERE rating > {0}", 7);
     #endif
     }
     /// Usage of parameters looks similar to `String.Format`, but instead of direct interpolation,
     /// they are transformed into fair ADO.NET command parameters to protect your queries from injection-attacks.
     ///
     {
     #if CODE
         var list = api.Find(
             "book",
             "WHERE release_date BETWEEN {0} and {1} AND author LIKE {2}",
             new DateTime(1930, 1, 1), new DateTime(1950, 1, 1), "%remarque%"
         );
     #endif
     }
     ///
     /// You can use any SQL as long as the result maps to a set of beans.
     /// For other cases, see [Generic Queries](#generic-sql-queries).
     ///
     /// To find a single bean:
     #if CODE
     var best = api.FindOne("book", "ORDER BY rating DESC LIMIT 1");
     #endif
     /// To find out the number of beans without loading them:
     #if CODE
     var count = api.Count("book", "WHERE rating > {0}", 7);
     #endif
     /// It is also possible to perform unbuffered (memory-optimized) load for processing in a foreach-loop:
     #if CODE
     foreach(var bean in api.FindIterator("book", "ORDER BY rating")) {
         // do something with bean
     }
     #endif
 }