Пример #1
0
        public static T FindOne(long id, IAdapterService adapterService = null)
        {
            QueryFindOneBuilder <T> newQuery = new QueryFindOneBuilder <T>();
            var returnQuery = newQuery.Where(query => query.Id == id);

            return((adapterService ?? ContextAdapterService).FindOne <T>(returnQuery));
        }
Пример #2
0
        public static T Load <T>(long id, IAdapterService adapterService = null) where T : IEntity, new()
        {
            var contextAdapterService     = (adapterService ?? DataContext.GetAdapterService <T>());
            QueryFindOneBuilder <T> query = Query.FindOne <T>().Where(x => x.Id == id);

            return(contextAdapterService.FindOne <T>(query));
        }
Пример #3
0
        public static T FindOne(Func <QueryFindOneBuilder <T>, QueryFindOneBuilder <T> > query, IAdapterService adapterService = null)
        {
            QueryFindOneBuilder <T> newQuery = new QueryFindOneBuilder <T>();
            var returnQuery = query(newQuery);
            var adapter     = (adapterService ?? ContextAdapterService);

            if (adapter == null)
            {
                throw new InvalidOperationException("Please add/configure a adapter service.");
            }

            return(adapter.FindOne <T>(returnQuery));
        }
Пример #4
0
        public static T FindOneOrCreate(QueryFindOneBuilder <T> query, T newEntity = default(T), IAdapterService adapterService = null)
        {
            T entity = FindOne(query, adapterService);

            if (entity == null)
            {
                if (EqualityComparer <T> .Default.Equals(newEntity, default(T)))
                {
                    entity = new T();
                }
                else
                {
                    entity = newEntity;
                }
                Insert(ref entity, adapterService);
            }
            return(entity);
        }
Пример #5
0
 public static T FindOne(QueryFindOneBuilder <T> query, IAdapterService adapterService = null)
 {
     return((adapterService ?? ContextAdapterService).FindOne <T>(query));
 }