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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:25:16+00:00 2026-06-13T10:25:16+00:00

For example:- // This one will be converted to SQL no problem Expression<Func<Foo, bool>>

  • 0

For example:-

// This one will be converted to SQL no problem
Expression<Func<Foo, bool>> predicate = x => x.Name = "Foo";

// This one will throw a NotSupportedException because the QueryProvider
// doesn't support reference comparisons
Expression<Func<Foo, bool>> predicate = x => x == someOtherFoo;

// This one doesn't work because the query provider can't
// handle IsAwesome()
Expression<Func<Foo, bool>> predicate = x => x.IsAwesome();

I’m looking for a way to test this before runtime, ideally in an automated test isolated from the database.

I spent some time trawling through MSDN trying to find how to instantiate my own QueryProvider, but my Google-fu appears to be failing me today.

Thanks in advance!

  • 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. Editorial Team
    Editorial Team
    2026-06-13T10:25:17+00:00Added an answer on June 13, 2026 at 10:25 am

    You need a model to do this, but you don’t need a database. You can create the model as an EDMX, but it’s probably easier to use Code First. To ensure that the creating or using the Code First model doesn’t need a database connection you will need to provide some information that Code First normally obtains from the database. This post http://blog.oneunicorn.com/2012/04/21/code-first-building-blocks/ shows how to use the DbModelBuilder to do this and how to create a DbContext from the model. You’ll end up with some code like this:

    var modelBuilder = new DbModelBuilder();
    modelBuilder.Entity<Foo>();
    var model = modelBuilder.Build(
                    new DbProviderInfo("System.Data.SqlClient", "2008")).Compile();
    

    You’ll probably want to cache the model object rather than create it again for every different test.

    You should also disable database initializers to prevent DbContext from attempting to connect to the database. For example, before using the context make a call like this:

    Database.SetInitializer<FooContext>(null);
    

    Now you can just use ToString on any query to see what SQL it will generate. If LINQ can’t handle the expression then you will get an exception. For example, this will print the query:

    using (var context = new FooContext(model))
    {
        Expression<Func<Foo, bool>> predicate = x => x.Name == "Foo";
    
        Console.WriteLine(context.Foos.Where(predicate));
    }
    

    This will throw:

    using (var context = new FooContext(model))
    {
        var someOtherFoo = new Foo();
        Expression<Func<Foo, bool>> predicate = x => x == someOtherFoo;
    
        Console.WriteLine(context.Foos.Where(predicate));
    }
    

    Obviously if you’re writing tests you won’t just be printing to the console, but rather performing some kind of assertions/checks.

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

Sidebar

Related Questions

Example: /** * This function will determine whether or not one string starts with
This is a follow-up question to this one . Consider this example: #include <iostream>
For example on any tinyurl/ajdeijad link (this one is fake), the think redirects to
for example, in this one, I 'm not very understand about the this pointer,
I am trying to display(block,none) select boxes(in this example only one select box) through
I use TCPDF for outputting an html table, this one in my example is
When I copy a YouTube link, like this one, for example (http://www.youtube.com/watch?v=_Ka2kpzTAL8), and paste
In this example I create three buttons 'one' 'two' 'three'. When clicked I want
example: at this domain http://www.example.com/234234/go.html is only one iframe-code how can i get the
From this example http://www.senchafiddle.com/#dPZn0 This displays a first panel, then a second one... using

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.