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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:35:35+00:00 2026-05-22T00:35:35+00:00

I have a Restaurant object, which contains a Menu . The Menu contains MenuItems

  • 0

I have a Restaurant object, which contains a Menu. The Menu contains MenuItems.

Via the Entity Framework Code First, I created a database and stored a single Restaurant in it, which has a single MenuItem. I’ve checked the database, and the MenuItem is there. However, it isn’t getting loaded when I retrieve the Restaurant object.

I tried implementing the [OnSerializing] attribute for the Menu object (since this is taking place in a WCF application), so as to “force” the MenuItems to be loaded, but that didn’t have any effect. I’ve also seen folks recommending the [IncludeAttribute], but that attribute exists in two assemblies, neither of which is present on my machine as far as I can tell.

I’ve attempted to turn on logging/tracing for the Entity framework, but so far without success.

Anyway, here is how I’ve got my data objects defined:

[DataContract]
public class MenuItem
{
    [DataMember]
    public int ID { get; set; }

    [DataMember]
    public string Description { get; set; }

    [DataMember]
    public string Price { get; set; }
}

[CollectionDataContract]
public class ListOfMenuItem : List<MenuItem>
{
}

[DataContract]
public class Menu
{
    /// <summary>
    /// Alternate constructor, used during serialization operation.
    /// </summary>
    /// <param name="pContext"></param>
    [OnDeserializing]
    public void OnDeserializing(StreamingContext pContext)
    {
        Init();
    }

    public Menu()
    {
        Init();
    }

    private void Init()
    {
        MenuItems = new ListOfMenuItem();
    }

    [DataMember]
    public int ID { get; set; }

    [DataMember]
    public ListOfMenuItem MenuItems
    {
        get;
        set;
    }
}

[DataContract]
public class Restaurant
{
    /// <summary>
    /// Alternate constructor, used during serialization operation.
    /// </summary>
    /// <param name="pContext"></param>
    [OnDeserializing]
    public void OnDeserializing(StreamingContext pContext)
    {
        Init();
    }

    public Restaurant()
    {
        Init();
    }

    private void Init()
    {
        Hours = new HoursOfOperation();
        Menu = new Menu();
    }

    /// <summary>
    /// Unique name and identifier for a restaurant.
    /// </summary>
    [DataMember(IsRequired = true)]
    [Key]
    public string Name
    {
        get;
        set;
    }

    /// <summary>
    /// What hours is the restaurant open.
    /// </summary>
    [DataMember]
    public HoursOfOperation Hours
    {
        get;
        set;
    }

    /// <summary>
    /// What does the restaurant have to eat and drink.
    /// </summary>
    [DataMember]
    public Menu Menu
    {
        get;
        set;
    }
}

And the database context is defined as:

public class RestaurantDirectory : DbContext
{
    public DbSet<Restaurant> Restaurants { get; set; }
}
  • 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-22T00:35:35+00:00Added an answer on May 22, 2026 at 12:35 am

    If you are using Entity Framework 4.1 on WCF, put this in your DbContext constructor

    this.Configuration.ProxyCreationEnabled = false;
    

    If you are using 4.0, use ContextOptions.ProxyCreationEnabled = false

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

Sidebar

Related Questions

I have a table called restaurants which contains each restaurant information, I want to
I have following code in a Spring Dao which works just fine - Object
I have the following tables category, Restaurant, and menu. A restaurant can have more
have written this little class, which generates a UUID every time an object of
I have a restaurant reservations site, which helps customers book an event at a
I have some HTML5 files in which I embedded XML through object element. Now,
I have an object that represents a food item to order at a restaurant.
I have a Array list which contains Objects of Restaurants ArrayList<Restaurants> array_sort = new
I have a database of restaurant reviews. I have three tables: restaurant , user
I have the following Django models: Bar, Bistro and Restaurant Each of the above

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.