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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:26:04+00:00 2026-06-03T15:26:04+00:00

I have a entity Player that has one to many association to other entities.

  • 0

I have a entity “Player” that has “one to many” association to other entities. When I clone one of my Player rows the entities that are associated with Player are not getting cloned. but the Player data row gets cloned. I need the assocations values to get cloned aswell. How can I do this?

Here is the code inside my respository

public Player CreateTemplate(Player player)
{
db.Detach(player);
Player.EntityKey = null;
db.AddToPlayer(player);
db.SaveChanges();
return player;
}

Here is my Action method:

public ActionResult CreatePlayerTemplate(int id)
{
var player = MyRepository.GetPlayerdByID(id);
MyRepository.CreateTemplate(player);
return View();
}

Update:
this how i retrieve Player :

 public Player GetPlayerByID(int id)
    {
        return db.Player.SingleOrDefault(x => x.Id == id);
    }
  • 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-03T15:26:05+00:00Added an answer on June 3, 2026 at 3:26 pm

    Alternative, kinda hacky approach – use mapping tool, like AutoMapper

    Define self-maps for every entity participating in cloning, and configure to ignore entity key

    Mapper.CreateMap<Player, Player>()
    .ForMember(x => x.EntityKey, y => y.Ignore());
    
    Mapper.CreateMap<SomeOtherEntity, SomeOtherEntity>()
    .ForMember(x => x.EntityKey, y => y.Ignore());
    

    And then just clone entities

    var clonnedPlayer = Mapper.Map<Player>(originalPlayer);
    

    Also, this way you could configure not to clone lookup-like tables to not duplicate lookup data

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

Sidebar

Related Questions

i have an entity Entity1 that have one to many relation with Entity2 as
I have entity e.g. Product which aggregates other entities such as Category . Those
In my business model I have Entity class (IPoint interface ) that has a
I have a Player Entity that is governed by gravity and I have another
I have an entity Roster that has a collection of players. public class Roster
I have a class Player that extends Entity: Player: public class Player extends Entity
I have entity Recipes and it has a HasMany collection comments. In a MVC
I have Entity Framework entities Events which have an EntityCollection of RSVP. I want
I have an Entity which holds a collection of OtherEntity in a many-to-many style
I have an entity set bound to a DataGridView where users can add/modify rows.

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.