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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:10:07+00:00 2026-05-23T10:10:07+00:00

My current problem seems like a mutant version of what I ran into a

  • 0

My current problem seems like a mutant version of what I ran into a few months ago (see: Problems updating w/ EF4 repo & MVC2 – can't update many-to-many graph). I can create a new Game-Platform graph, but I can’t edit the Platform side of an existing graph. So, I can’t add/remove Platforms from the relationship.

I’m using AutoMapper to map the incoming data to entities. I’m then manually attaching the Game entity to the ObjectContext in my repository, and manually setting its EntityState based on whether I’m creating a new entity graph, or updating an existing one. Here’s my current setup:

AutoMapper mapping:

Mapper.CreateMap<AdminGameEditModel, Game>()
    .BeforeMap((s, d) =>
    {
        foreach (var platId in s.PlatformIDs)
        {
            Platform newPlat = _gameRepository.GetPlatform(platId);

            d.Platforms.Add(newPlat);
        }
    })
    .ForMember(dest => dest.BoxArtPath, opt => opt.Ignore())
    .ForMember(dest => dest.IndexImagePath, opt => opt.Ignore())
    .ForMember(dest => dest.Cons, opt => opt.MapFrom(src => String.Join("|", src.Cons)))
    .ForMember(dest => dest.Pros, opt => opt.MapFrom(src => String.Join("|", src.Pros)))
    .ForMember(dest => dest.LastModified, opt => opt.UseValue(DateTime.Now))
    .ForMember(dest => dest.Platforms, opt => opt.Ignore());

The GetPlatform method of my repo:

public Platform GetPlatform(int id)
{
    Platform plat = _siteDB.Platforms.FirstOrDefault(pl => pl.PlatformID == id);
    _siteDB.Detach(plat);

    return plat;
}

And my SaveGame method:

public void SaveGame(Game game)
{
    _siteDB.Games.Attach(game);

    if (game.GameID > 0)
    {
        _siteDB.ObjectStateManager.ChangeObjectState(game, System.Data.EntityState.Modified);
    }
    else
    {
        _siteDB.ObjectStateManager.ChangeObjectState(game, System.Data.EntityState.Added);
    }

    _siteDB.SaveChanges();
}

My only thought is that I need to Remove() the Platforms of the existing Game entity. I’m not sure how to do that gracefully with my current setup as I already have an incoming fresh Game entity being sent to SaveGame() that has the new list of Platforms. I feel like there has to be a better, more graceful way of doing things.

So, any ideas? I’m trying to keep references to my UI (view/edit models and the like) from creeping into my domain layer, so I don’t want my repo to deal with my AdminGameEditModel directly.

  • 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-23T10:10:07+00:00Added an answer on May 23, 2026 at 10:10 am

    There is no way to do it gracefully. What you have to do is:

    • Get your view model as is (a new state)
    • Load the Game from the database together with all its platforms (current persisted state)
    • Write a code which will go through the new state and add or modify platforms in the current state
    • Write a code which will go through the current state and remove all platforms not included in the new state
    • Save changes

    Simply once you post new state from the view where you removed some platforms you lost the information about them and you must first load the current state from database to find which platforms you must delete.

    Another more brutal approach is loading current state, clearing platform collection (all relations are removed) and then add all platforms from the new state.

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

Sidebar

Related Questions

This seems like a fairly simple problem to me but I have been having
this seems like such a simple problem but I have been unable to find
This seems like basic problem, but I'm struggling with it (maybe because of tiredness).
This seems like such a trivial problem, but I can't seem to pin how
This seems like something neat that might be built into jQuery but I think
I have what seems like a simple problem in my Rails 3.1 app: I
So this seems like a simple little problem, but I haven't been successful with
My current problem is that I have a JFrame with a 2x2 GridLayout. And
I want to fix the Background while only the ListFields scrolls. Current Problem: Scrolling
I'm trying to write a re-usable .NET Assembly that implements WCF. My current problem

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.