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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:45:19+00:00 2026-05-15T08:45:19+00:00

(This looks like a long question, but it’s not really, honest!) I am trying

  • 0

(This looks like a long question, but it’s not really, honest!)

I am trying to get a simple proof of concept working with Entity Framework 4 and the CTP 3 version of Code Only. It feels like I’m missing something really obvious and simple.

I have this following test which is failing:

[TestFixture]
public class ParentChildTests
{
    [Test]
    public void ChildRead_DatabaseContainsRelatedObjects_ParentIsNotNull()
    {
        var ctx = GetMyObjectContext();
        var child = ctx.Children.Where(c => c.Id == 1).Single();
        var parent = child.ParentTable;
        Assert.That(parent, Is.Not.Null);
    }

    // GetMyObjectContext etc...
}

The read of child works fine and I get back a ChildTable whose ParentTableId value is ‘1’ as I would expect, but the ParentTable property is NULL. I do not expect this because my POCOs have all virtual properties (see below) and EF4 has lazy loading enabled by default.

What am I missing?


Database

create table parent_table
(
    parent_table_id   int identity(1,1) primary key,
    parent_table_name varchar(50) not null,
    display_name      varchar(50)
)

create table child_table
(
    child_table_id   int identity(1,1) primary key,
    child_table_name varchar(50) not null,
    parent_table_id  int not null
)

alter table child_table add constraint FK_child_table__parent_table
foreign key (parent_table_id) references parent_table(parent_table_id)

POCO Entities

public class ParentTable
{
    public virtual int    Id          { get; set; }
    public virtual string Name        { get; set; }
    public virtual string DisplayName { get; set; }
}

public class ChildTable
{
    public virtual int         Id            { get; set; }
    public virtual string      Name          { get; set; }
    public virtual int         ParentTableId { get; set; }
    public virtual ParentTable ParentTable   { get; set; }
}

Entity Configurations

public class ParentTableConfiguration : EntityConfiguration<ParentTable>
{
    public ParentTableConfiguration()
    {
        MapSingleType(pt => new
        {
            parent_table_id   = pt.Id,
            parent_table_name = pt.Name,
            display_name      = pt.DisplayName,
        })
        .ToTable("dbo.parent_table");

        Property( pt => pt.Id   ).IsIdentity();
        Property( pt => pt.Name ).IsRequired();
    }
}

public class ChildTableConfiguration : EntityConfiguration<ChildTable>
{
    public ChildTableConfiguration()
    {
        MapSingleType(ct => new
        {
            child_table_id   = ct.Id,
            child_table_name = ct.Name,
            parent_table_id  = ct.ParentTableId,
        })
        .ToTable("dbo.child_table");

        Property( ct => ct.Id   ).IsIdentity();
        Property( ct => ct.Name ).IsRequired();

        Relationship(ct => ct.ParentTable)
            .HasConstraint((ct, pt) => ct.ParentTableId == pt.Id);
    }
}

(Thanks for reading this far!)

  • 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-15T08:45:19+00:00Added an answer on May 15, 2026 at 8:45 am

    As far as understand you just do not load this navigation property.

    This will result in eager loading.

    var child = ctx.Children.Include("ParentTable").Where(c => c.Id == 1).Single();

    Or you could enable lazy loading by setting ctx.ContextOptions.LazyLoadingEnabled = true;

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

Sidebar

Related Questions

This answer to what looks like the same question: Convert integer to hex and
Okay. I know this looks like the typical Why didn't he just Google it
I know at first glance (due to the title) this looks like one of
Update: looks like this is indeed a WiX limitation - Cannot add 64bit com+
My code looks like this NSNumber *inputToNumber = [NSNumber numberWithFloat:[textField.text floatValue]]; the value from
Suppose your git history looks like this: 1 2 3 4 5 1–5 are
The original query looks like this (MySQL): SELECT * FROM books WHERE title LIKE
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a query that looks like this: public IList<Post> FetchLatestOrders(int pageIndex, int recordCount)
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)

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.