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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:49:35+00:00 2026-05-28T17:49:35+00:00

I have a problem that I haven’t been able to find a solution to,

  • 0

I have a problem that I haven’t been able to find a solution to, and I wonder if anyone could give some advice.

I have a mocked datacontext/objectset, done through interfaces and t4 templates, with some ninject magic, with the intent of having in memory datasets for unit testing.

However, what should you do with the foreign key values/navigation properties?

Lets say I have hotels and customers, ctx.Hotels has some values, but Customer.Hotels does not. The get is something like this if it is a one-to-one relationship:

return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedReference<Hotel>("HotelModel.FK_Customers_Hotels", "Hotel").Value;

and one-to-many:

return ((IEntityWithRelationships)this).RelationshipManager.GetRelatedCollection<BookingRow>("HotelModel.FK_BookingRows_Customers", "BookingRow");

My skill level just isn’t enough to even understand what is going on here.

[edit:]
Great Master Julie Lerman confirms that this is a dead end. You can’t properly mock entityobjects, you need POCOs for that.

  • 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-28T17:49:36+00:00Added an answer on May 28, 2026 at 5:49 pm

    Mocking ObjectContext when you are using EntityObject based entities is mostly impossible because for example RelationshipManager is a real class which cannot be replaced with your mock. Also your entities are heavily dependent on non mockable EF code.

    Note: “Mostly” because you can mock it but you need special framework intercepting calls to real objects and forwarding them to your methods instead. That is possible only with TypeMock Isolator or MS Moles.

    Btw. mocking EF code is something you don’t want to do – go through this answer and linked answers. Some of them targets newer EF API but the problems are still same.

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

Sidebar

Related Questions

I have a problem that seems like there should be a simple solution but
We have the problem that we have the open project files in our SVN
I have a problem that I have not faced before: It seems that the
In a couple of scripts that I use I have problem that is intermittent.
I have encountered a problem that I have not come accross yet when setting
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone
I have a problem that seems like its a result of a deadlock-situation. Whe

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.