コード例 #1
0
        static int DefaultNewIdGenerator(Type type)
        {
            if (type.BaseType != typeof(IntEntity))
            {
                return(DefaultNewIdGenerator(type.BaseType));
            }

            Func <Type, int> initialize = (t =>
            {
                if (TransientEntityAttribute.IsTransient(t))
                {
                    return(1);
                }

                return(Database.GetList(t, new[] { QueryOption.Take(1), QueryOption.OrderByDescending("ID") })
                       .FirstOrDefault().Get(x => (int)x.GetId() + 1) ?? 1);
            });

            return(LastUsedIds.AddOrUpdate(type, initialize, (t, old) => old + 1));
        }
コード例 #2
0
 /// <summary>
 /// Finds an object with the specified type matching the specified criteria.
 /// If not found, it returns null.
 /// </summary>
 public static T Find <T>(Expression <Func <T, bool> > criteria, params QueryOption[] options) where T : IEntity
 {
     options = options ?? new QueryOption[0];
     options = options.Concat(QueryOption.Take(1)).ToArray();
     return(GetList <T>(criteria, options).FirstOrDefault());
 }
コード例 #3
0
 /// <summary>
 /// Find an object with the specified type from the database.
 /// When used with no criteria, returns the first object found of the specified type.
 /// If not found, it returns null.
 /// </summary>
 /// <param name="orderBy">The order by expression to run at the database level. It supports only one property.</param>
 /// <param name="desc">Specified whether the order by is descending.</param>
 public static T Find <T>(Expression <Func <T, bool> > criteria, Expression <Func <T, object> > orderBy, bool desc = false) where T : IEntity
 {
     return(GetList <T>(criteria, QueryOption.OrderBy <T>(orderBy, desc), QueryOption.Take(1)).FirstOrDefault());
 }
コード例 #4
0
 /// <summary>
 /// Find an object with the specified type from the database.
 /// When used with no criteria, returns the first object found of the specified type.
 /// If not found, it returns null.
 /// </summary>
 public static T Find <T>(params Criterion[] criteria) where T : IEntity
 {
     return(GetList <T>(criteria, QueryOption.Take(1)).FirstOrDefault());
 }