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

  • Home
  • SEARCH
  • 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 6386149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:59:16+00:00 2026-05-25T02:59:16+00:00

i stumbled to the next problem… I have database context: // For support unit

  • 0

i stumbled to the next problem… I have database context:

// For support unit testing... 
public interface IDbContext : IDisposable
{
   IQueryable<Hardware> Hardwares { get; }
   IQueryable<ProviderHardware> ProviderHardwares { get; }
}

// Real DbContext (EF 4.0, Code First)
public class PrimaryDbContext : DbContext, IDbContext
{
   public DbSet<Hardware> Hardwares { get; set; }
   public DbSet<ProviderHardware> ProviderHardwares { get; set; }

   IQueryable<Hardware> IDbContext.Hardwares
     { get { return Hardwares; } }
   IQueryable<ProviderHardware> IDbContext.ProviderHardwares
     { get { return ProviderHardwares; } } 
   ...
}

And i try get all hardwares, which doesnt exists in ProviderHardwares table:

var hardwaresRemoved = db.Hardwares.Where(i => (i.IsAvailable == true) &&
   (db.ProviderHardwares.Count(j => j.Article == i.Article) == 0)).ToList();

If i use PrimaryDbContext strictly such as “PrimaryDbContext db = new PrimaryDbContext();” all work fine. But if i use it implicitly “IDbContext db = new PrimaryDbContext();” that i get an exception:

Unable to create a constant value of type
‘ConfiguratorMvcApplication.DomainModels.ProviderHardware’. Only
primitive types (‘such as Int32, String, and Guid’) are supported in
this context.

Summarize, i can’t replace a DbSet on an IQueryable. And how i can use unit testing in this case? I hope someone have resolved this problem yet…
Thank in advance very much!

  • 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-05-25T02:59:17+00:00Added an answer on May 25, 2026 at 2:59 am

    I suggest you better keep DbSets and do INTEGRATION TESTING including the database.

    Because, although passing a unit test with a mock of a DB could be somewhat usefull, you are going to be better off testing with real database (but it’s not unit testing).

    On the ClassInitialize erase the database and/or create the initial data for testing.

    If you create an App.config file with a connection string you can have a separate test database, and if you are using EF Code First, you get it for free.

    Best regards.

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

Sidebar

Related Questions

I stumbled over this passage in the Django tutorial : Django models have a
I stumbled across this problem in F#. Suppose, I want to declare two types
I just stumbled over a small problem when extending javascript objects using jQuery. When
I have stumbled upon a bug in Safari on iPad. $('#next_proj a').trigger('click'); .. does
Stumbled over that def foo(f: Int => Unit) {} def foo(f: Long => Unit)
I stumbled upon this site http://nathanborror.com/ and really loved the way they have done
I have next mission: i have to replace flash alement with javascript in this
I'm, let's say, new to jquery. I've stumbled across a quite interesting problem. I`ve
I've just stumbled upon this problem on the net. It kind of goes something
I've debugging some problem with a Paint.Net plugin and I've stumbled with some issue

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.