Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following is a partial of my DB Schema.

https://drive.google.com/file/d/0Bx3eJEwRdRm5MkNDcjBoSGI1NVE/view?usp=sharing

I have two lists containing parentNames and the leafNames I need. Now, I need to copy the required records from one entity's tables to a newly created entity's tables.

Cloning is really not an option here. How can this be done?

I have tried:

C#
var originalEntity = _entity.ParentTable.Include("ParentToChildTable")
                           .Include("ParentToChildTable.ChildTable")
                           .Include("ParentToChildTable.ChildTable.LeafTable")
                      .AsNoTracking().Where(a => parentNames.Contains(a.Name));

_NewEntity.ParentTable.AddRange(originalEntity);
_NewEntity.SaveChanges();

But this copies all the records associated. And I can't figure out how to go about selecting LeafTable's records.
Posted
Comments
Maciej Los 10-Mar-15 3:35am    
What you mean by "selecting LeafTable's records"?
Swetaketu Majumder 10-Mar-15 12:34pm    
I want to copy only a few records from the Leaftable keeping the relationships intact.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900