Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 89937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:47:42+00:00 2026-05-10T22:47:42+00:00

I was wondering if anyone had a better idea how to do this. atm

  • 0

I was wondering if anyone had a better idea how to do this. atm returning IQueryable<Member> as ObjectQuery<Member> seems dirty to me.

namespace Falcon.Business.Repositories {     using System;     using System.Data.Objects;     using System.Linq;     using Falcon.Business.Criteria;     using Falcon.Business.Entities;     using Falcon.Business.Enums;     using Falcon.Business.Extensions;     using Falcon.Business.Repositories.Interfaces;     using Falcon.Business.Services;     using Falcon.Business.Services.Interfaces;     using Falcon.Core.Extensions;      public class MemberRepository : LinqRepository<Member>, IMemberRepository     {         public Member Fetch(MemberCriteria criteria)         {             ObjectQuery<Member> query = base.CreateQuery();              query = this.AddRelations(query);             query = this.AddCriteria(query, criteria);             query = this.AddCriteriaOrder(query, criteria);              return query.FirstOrDefault();         }          public IPagerService<Member> FetchAll(MemberCriteria criteria)         {             int page = (criteria.Page.HasValue) ? criteria.Page.Value : 1;             int limit = criteria.Limit;             int start = (page * limit) - limit;             int total = this.Count(criteria);              ObjectQuery<Member> query = base.CreateQuery();              query = this.AddRelations(query);             query = this.AddCriteria(query, criteria);             query = this.AddCriteriaOrder(query, criteria);              return new PagerService<Member>(query.Skip(start).Take(limit).ToList(), page, limit, total);         }          public int Count(MemberCriteria criteria)         {             ObjectQuery<Member> query = base.CreateQuery();              query = this.AddCriteria(query, criteria);              return query.Count();         }          public ObjectQuery<Member> AddCriteria(IQueryable<Member> query, MemberCriteria criteria)         {             if (criteria.Title.HasValue())             {                 query = query.Where(q => q.Title == criteria.Title);             }              if (criteria.TitleUrl.HasValue())             {                 query = query.Where(q => q.TitleUrl == criteria.TitleUrl);             }              if (criteria.EmailAddress.HasValue())             {                 query = query.Where(q => q.EmailAddress == criteria.EmailAddress);             }              if (criteria.HostAddress.HasValue())             {                 query = query.Where(q => q.HostAddress == criteria.HostAddress);             }              query = query.Where(q => q.Status == criteria.Status);              return query as ObjectQuery<Member>;         }          public ObjectQuery<Member> AddCriteriaOrder(IQueryable<Member> query, MemberCriteria criteria)         {             if (criteria.Sort == SortMember.ID)             {                 query = criteria.Order == SortOrder.Asc                     ? query.OrderBy(q => q.ID)                     : query.OrderByDescending(q => q.ID);             }             else if (criteria.Sort == SortMember.Posts)             {                 query = criteria.Order == SortOrder.Asc                     ? query.OrderBy(q => q.Posts)                     : query.OrderByDescending(q => q.Posts);             }             else if (criteria.Sort == SortMember.Title)             {                 query = criteria.Order == SortOrder.Asc                     ? query.OrderBy(q => q.Title)                     : query.OrderByDescending(q => q.Title);             }             else if (criteria.Sort == SortMember.LastLogin)             {                 query = criteria.Order == SortOrder.Asc                     ? query.OrderBy(q => q.LastLogin)                     : query.OrderByDescending(q => q.LastLogin);             }             else if (criteria.Sort == SortMember.LastVisit)             {                 query = criteria.Order == SortOrder.Asc                     ? query.OrderBy(q => q.LastVisit)                     : query.OrderByDescending(q => q.LastVisit);             }             else             {                 query = criteria.Order == SortOrder.Asc                     ? query.OrderBy(q => q.Created)                     : query.OrderByDescending(q => q.Created);             }              return query as ObjectQuery<Member>;         }          private ObjectQuery<Member> AddRelations(ObjectQuery<Member> query)         {             query = query.Include(x => x.Country);             query = query.Include(x => x.TimeZone);             query = query.Include(x => x.Profile);              return query;         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:47:42+00:00Added an answer on May 10, 2026 at 10:47 pm

    I also do not like returning an objectquery, because doing so will make you very dependent on Entity Framwork. Knowing Microsoft they propably make a lot of changes in version 2, so you do not want to do this.

    NHibernate uses criteria, a bit like you suggested, but their implementation is a lot more generic. I like the more generic implementation more then you example because then you do not need to build criteria for every object. On the other hand, you implementation is typed, which is also very neat. If you want the best of both, a more generic implementation that is typed, you might want to take a look at the NHibernate implementation but instead of using strings, use lambda functions and .Net generics. I could post an example how to do this, but I’m currently not on my own machine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if anyone had an idea as to why the code below
I have been stuck on this for days, and was wondering if anyone had
Was just wondering if anyone had any simple ideas to do this. Effectively I'd
I'm struggling with this using timeit and was wondering if anyone had any tips
Was wondering if anyone had any smart approaches to creating dynamic vanity user urls
I was wondering if anyone had developed an approach for using NHibernate / Fluent
I was wondering if anyone had an opinion on what they think is the
I was wondering if anyone had any advice on parsing a file with fixed
I was just wondering if anyone had any experience with more customized/specified theme rolling?
I was wondering if anyone had experience of trying to get Eth to enter

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.