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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:40:36+00:00 2026-05-12T09:40:36+00:00

Given two tables, Make and Model, where a make can contain many models and

  • 0

Given two tables, Make and Model, where a make can contain many models and resulting in the following EF generated entity types…

/// <KeyProperties>
/// ID
/// </KeyProperties>
[global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName="CarsModel", Name="Make")]
[global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)]
[global::System.Serializable()]
public partial class Make : global::System.Data.Objects.DataClasses.EntityObject
{
    /// <summary>
    /// Create a new Make object.
    /// </summary>
    /// <param name="id">Initial value of ID.</param>
    public static Make CreateMake(int id)
    {
        Make make = new Make();
        make.ID = id;
        return make;
    }
    /// <summary>
    /// There are no comments for Property ID in the schema.
    /// </summary>
    [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public int ID
    {
        get
        {
            return this._ID;
        }
        set
        {
            this.OnIDChanging(value);
            this.ReportPropertyChanging("ID");
            this._ID = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value);
            this.ReportPropertyChanged("ID");
            this.OnIDChanged();
        }
    }
    private int _ID;
    partial void OnIDChanging(int value);
    partial void OnIDChanged();
    /// <summary>
    /// There are no comments for Property Name in the schema.
    /// </summary>
    [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public string Name
    {
        get
        {
            return this._Name;
        }
        set
        {
            this.OnNameChanging(value);
            this.ReportPropertyChanging("Name");
            this._Name = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);
            this.ReportPropertyChanged("Name");
            this.OnNameChanged();
        }
    }
    private string _Name;
    partial void OnNameChanging(string value);
    partial void OnNameChanged();
    /// <summary>
    /// There are no comments for Models in the schema.
    /// </summary>
    [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("CarsModel", "FK_Model_Make", "Model")]
    [global::System.Xml.Serialization.XmlIgnoreAttribute()]
    [global::System.Xml.Serialization.SoapIgnoreAttribute()]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public global::System.Data.Objects.DataClasses.EntityCollection<Model> Models
    {
        get
        {
            return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedCollection<Model>("CarsModel.FK_Model_Make", "Model");
        }
        set
        {
            if ((value != null))
            {
                ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedCollection<Model>("CarsModel.FK_Model_Make", "Model", value);
            }
        }
    }
}

/// <KeyProperties>
/// ID
/// </KeyProperties>
[global::System.Data.Objects.DataClasses.EdmEntityTypeAttribute(NamespaceName="CarsModel", Name="Model")]
[global::System.Runtime.Serialization.DataContractAttribute(IsReference=true)]
[global::System.Serializable()]
public partial class Model : global::System.Data.Objects.DataClasses.EntityObject
{
    /// <summary>
    /// Create a new Model object.
    /// </summary>
    /// <param name="id">Initial value of ID.</param>
    public static Model CreateModel(int id)
    {
        Model model = new Model();
        model.ID = id;
        return model;
    }
    /// <summary>
    /// There are no comments for Property ID in the schema.
    /// </summary>
    [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public int ID
    {
        get
        {
            return this._ID;
        }
        set
        {
            this.OnIDChanging(value);
            this.ReportPropertyChanging("ID");
            this._ID = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value);
            this.ReportPropertyChanged("ID");
            this.OnIDChanged();
        }
    }
    private int _ID;
    partial void OnIDChanging(int value);
    partial void OnIDChanged();
    /// <summary>
    /// There are no comments for Property Name in the schema.
    /// </summary>
    [global::System.Data.Objects.DataClasses.EdmScalarPropertyAttribute()]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public string Name
    {
        get
        {
            return this._Name;
        }
        set
        {
            this.OnNameChanging(value);
            this.ReportPropertyChanging("Name");
            this._Name = global::System.Data.Objects.DataClasses.StructuralObject.SetValidValue(value, true);
            this.ReportPropertyChanged("Name");
            this.OnNameChanged();
        }
    }
    private string _Name;
    partial void OnNameChanging(string value);
    partial void OnNameChanged();
    /// <summary>
    /// There are no comments for Make in the schema.
    /// </summary>
    [global::System.Data.Objects.DataClasses.EdmRelationshipNavigationPropertyAttribute("CarsModel", "FK_Model_Make", "Make")]
    [global::System.Xml.Serialization.XmlIgnoreAttribute()]
    [global::System.Xml.Serialization.SoapIgnoreAttribute()]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public Make Make
    {
        get
        {
            return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Make>("CarsModel.FK_Model_Make", "Make").Value;
        }
        set
        {
            ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Make>("CarsModel.FK_Model_Make", "Make").Value = value;
        }
    }
    /// <summary>
    /// There are no comments for Make in the schema.
    /// </summary>
    [global::System.ComponentModel.BrowsableAttribute(false)]
    [global::System.Runtime.Serialization.DataMemberAttribute()]
    public global::System.Data.Objects.DataClasses.EntityReference<Make> MakeReference
    {
        get
        {
            return ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.GetRelatedReference<Make>("CarsModel.FK_Model_Make", "Make");
        }
        set
        {
            if ((value != null))
            {
                ((global::System.Data.Objects.DataClasses.IEntityWithRelationships)(this)).RelationshipManager.InitializeRelatedReference<Make>("CarsModel.FK_Model_Make", "Make", value);
            }
        }
    }

I am trying to store an instance of the Make class into ASP.NET ViewState, along with the associated models as follows…

private Make Make {
  get { return this.ViewState[@"EditContext"] as Make; }
  set { this.ViewState[@"EditContext"] = value; }
}

and

this.Make = (from make in context.Makes.Include(@"Models")
             where make.ID == 1
             select make).FirstOrDefault();

But upon PostBack, this.Make.Models is always empty (depite definitely being populated when the entity was placed into the ViewState.

According to the MS Help,

Because entity types support binary
serialization, objects can be saved in
the view state of an ASP.NET
application during a postback
operation. When required, the object
and its related objects are retrieved
from the view state and attached to an
existing object context.

I would therefore expect what I am doing to work. Can anybody explain why this is not the case?

Thanks.

  • 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-12T09:40:36+00:00Added an answer on May 12, 2026 at 9:40 am

    It seems that the problem was my own fault.
    After adding the entity to the ViewState, I was manually detaching it from the object context. This was then clearing the links between the Make and the associated Model objects.

    By simply adding the object to the ViewState without calling context.Detach(), the Models remain in the list, and I can still call context.Attach() to facilitate the manipulation of the object during the postback.

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

Sidebar

Ask A Question

Stats

  • Questions 201k
  • Answers 201k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Alternatively, R has many tools available for text mining, and… May 12, 2026 at 8:06 pm
  • Editorial Team
    Editorial Team added an answer Are you trying to set the max width/height and add… May 12, 2026 at 8:06 pm
  • Editorial Team
    Editorial Team added an answer You're right: The need for this class has been largely… May 12, 2026 at 8:06 pm

Related Questions

I'm using nested sets (aka modified preorder tree traversal) to store a list of
I have a Character model and a Link model. The Link model represents a
I'm playing around with LinqToSQL using an existing multi-lingual database, but I'm running into
Given a table of models 'A', that can have multiple child models 'B', of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.