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 4027272
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:04:34+00:00 2026-05-20T11:04:34+00:00

I’m looking for best practices regarding abstracting my RIA domain context away from my

  • 0

I’m looking for best practices regarding abstracting my RIA domain context away from my view models to make them data source agnostic. It seems like the best solution I can find is the service agent pattern as described here. However, what if I have some relatively complex query logic to perform?

For example, currently I have my domain contexts in my view models. Let’s say I have a ContactSearchViewModel, where there is a bit of logic involved in constructing the search query:

protected EntityQuery<Contact> CreateSearchQuery()
    {
        var query = Context.GetContactsQuery().Where(
                        e => e.First_Name.ToLower().StartsWith(FirstNameSearch.ToLower()) &&
                        e.Last_Name.ToLower().StartsWith(LastNameSearch.ToLower()));
        if (!string.IsNullOrEmpty(Phone))
        {
            query = query.Where(q => q.Phone == Phone ||
                                     q.Mobile == Phone ||
                                     q.Work == Phone);
        }
        if (SelectedContactType == "Prospect")
        {
            query = query.Where(q => q.Contact_Type_Id == 1);
        }
        else if (SelectedContactType == "Customer")
        {
            query = query.Where(q => q.Contact_Type_Id == 2);
        }
        return query;
    }

Now I could of course have a service agent method with a signature that looks something like public EntityList<Contact> SearchContacts(string firstName, string lastName, string phone, ContactType contactType) but imagine if my search queries were even more complex – this interface would become unwieldy. Is there a better alternative, some way I could construct the query in the VM like I do with the domain context? Or should I just suck it up and use some parameter objects?

I would very much prefer to be able to construct the queries on the VM, because I currently have a small hierarchy of VMs which all perform various searches using a base search class and template method for generating queries, kind of like

enter image description here

Not being able to generate queries from the client would cause a lot of code duplication that I fixed using this inheritance structure.

  • 1 1 Answer
  • 1 View
  • 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. Editorial Team
    Editorial Team
    2026-05-20T11:04:35+00:00Added an answer on May 20, 2026 at 11:04 am

    I would suggest looking into the Repository pattern. It’s part of DDD, but has application in any architecture, IMO. It’s purpose is to house query logic.

    It seems dirty to give your VM objects query logic, unless that is their single purpose.

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

Sidebar

Related Questions

I have a view passing on information from a database: def serve_article(request, id): served_article
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.