Exemple #1
0
        /// <summary>
        /// Links the current Bean with another Bean in a m:n relational manner and
        /// provides data (linkProps) for the Link.
        /// </summary>
        /// <param name="bean">Bean to be linked.</param>
        /// <param name="linkProps">Dictionary of Link Properties.</param>
        /// <returns>true, if successful</returns>
        public bool LinkWith(Bean bean, IDictionary <string, object> linkProps = null)
        {
            var ls = GetLinkScenario(bean.GetKind());

            var linkedKindPkValue = bean.GetKeyValue();

            var linkBean = Api.FindOne(false, ls.LinkKind,
                                       "WHERE " + ls.LinkingKindFkName + " = {0} AND " + ls.LinkedKindFkName + " = {1}",
                                       ls.LinkingKindPkValue, linkedKindPkValue);

            if (linkBean != null)
            {
                throw LinkAlreadyExistsException.New(ls.LinkingKind, ls.LinkedKind);
            }

            linkBean = Api.Dispense(ls.LinkKind);

            if (linkProps != null)
            {
                linkBean.Import(linkProps);
            }

            linkBean
            .Put(ls.LinkingKindFkName, ls.LinkingKindPkValue)
            .Put(ls.LinkedKindFkName, linkedKindPkValue)
            .Store();

            return(true);
        }
Exemple #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 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
        }
Exemple #3
0
 public static Book FindBook(string isbn)
 {
     return(DbConnection.FindOne <Book>("WHERE isbn_10 = {0} OR isbn_13 = {0}", isbn));
 }
Exemple #4
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
 }