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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:47:05+00:00 2026-06-07T12:47:05+00:00

I have a Tablo object, which has a reference to a Ressam object. In

  • 0

I have a Tablo object, which has a reference to a Ressam object. In my Edit action for Tablo, I want to be able to change the Ressam reference too, i.e referencing another RessamId. Here’s the controller code, let’s say I only want to change the Ressam of the Tablo in my call:

    [HttpPost]
    public ActionResult EditTablo(Tablo tablo, int? RessamId, HttpPostedFileBase image)
    {
        // Here, I successfully get RessamId, no problem there
        if (ModelState.IsValid)
        {

            // this is where I attach the Tablo object
            if (tablo is TuvalBaski)
            {
                container.Urun.Attach((TuvalBaski)tablo);
            }
            else if (tablo is YagliBoya)
            {
                container.Urun.Attach((YagliBoya)tablo);
            }

            // and this is the part where I change the Ressam reference
            if (RessamId == null)
            {
                tablo.Ressam = null;

                container.Ressam.Attach(tablo.Ressam);
                TryUpdateModel(tablo.Ressam);
            }
            else
            {

                tablo.Ressam = (from table in container.Ressam
                                where table.RessamId == RessamId
                                select table).Single();

                //container.Ressam.Context.ObjectStateManager.ChangeObjectState(tablo.Ressam, System.Data.EntityState.Modified);
                //container.ObjectStateManager.ChangeObjectState(tablo.Ressam, System.Data.EntityState.Modified);

                container.Ressam.Attach(tablo.Ressam);
                TryUpdateModel(tablo.Ressam);
            }

        return View(tablo);
    }

By the way, this doesn’t work. How can I update the reference id in my Tablo entity, so that it can show another Ressam?

  • 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-06-07T12:47:06+00:00Added an answer on June 7, 2026 at 12:47 pm

    Without much talk, here’s the code that does the job:

           [HttpPost]
            public ActionResult EditTablo(Tablo tablo, int? RessamId, HttpPostedFileBase image)
            {
                if (ModelState.IsValid)
                {
                    if (tablo is TuvalBaski)
                    {
                        container.Urun.Attach((TuvalBaski)tablo);
                    }
                    else if (tablo is YagliBoya)
                    {
                        container.Urun.Attach((YagliBoya)tablo);
                    }
    
                    if (RessamId == null)
                    {
                        if(tablo.Ressam != null)
                        {
                            container.Ressam.Detach(tablo.Ressam);
                        }
    
                        tablo.Ressam = null;
                    }
                    else
                    {
                        if (tablo.Ressam != null)
                        {
                            container.Ressam.Detach(tablo.Ressam);
                        }
    
                        tablo.Ressam = (from table in container.Ressam
                                        where table.RessamId == RessamId
                                        select table).Single();
    
    
                        container.Ressam.Attach(tablo.Ressam);
                    }
    
                    TryUpdateModel(tablo);
                    container.SaveChanges();
                }
    
                return View(tablo);
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Generic List object which hold below table as its own value.
I have an important Object which have loads of properties. Now few of the
I have a core data object that has a bunch of optional values. I'm
I have a JSF page which has a variable number inputText elements containing numeric
I have a common superclass (suppose it's Employee ), which has (amongst others) subclasses
Basically what I'm trying to achieve is to make the object reference another object
This is an odd question. But here goes. I have object X, which gets
I have a table on a iSeries(IBM-i/AS400) which has some constraints. The table is
Ok, here's my problem. I have a boost object which creates xml string via
Apologies for the vague question. Here it is: I have a table object created

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.