Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Cloning the Entity object and all related children using the Entity Framework

, 8 May 2012
Cloning the Entity object and all its children using the Entity Framework, using LINQ and Reflection.
CloningSample.zip
CloningSample
CloningSample.suo
CloningSample.Tests
bin
Debug
CloningSample.dll
CloningSample.pdb
CloningSample.Tests.dll
CloningSample.Tests.pdb
Controllers
obj
Debug
CloningSample.Tests.csprojResolveAssemblyReference.cache
CloningSample.Tests.dll
CloningSample.Tests.pdb
DesignTimeResolveAssemblyReferencesInput.cache
TempPE
Properties
CloningSample
App_Data
bin
CloningSample.dll
CloningSample.pdb
CloningSample.csproj.user
Content
Controllers
DBScripts
Global.asax
Models
EmpModel.edmx
obj
Debug
CloningSample.csprojResolveAssemblyReference.cache
CloningSample.dll
CloningSample.pdb
DesignTimeResolveAssemblyReferencesInput.cache
edmxResourcesToEmbed
Models
EmpModel.csdl
EmpModel.msl
EmpModel.ssdl
TempEdmx
TempPE
Models.EmpModel.Designer.cs.dll
Properties
Scripts
Views
Account
Employeemaster
Home
Shared
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<CloningSample.Models.Employee>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ViewPage1
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>ViewPage1</h2>

    <fieldset>
        <legend>Fields</legend>
        
        <div class="display-label">EMPID</div>
        <div class="display-field"><%: Model.EMPID %></div>
        
        <div class="display-label">FirstName</div>
        <div class="display-field"><%: Model.FirstName %></div>
        
        <div class="display-label">LastName</div>
        <div class="display-field"><%: Model.LastName %></div>
        
        <div class="display-label">MailId</div>
        <div class="display-field"><%: Model.MailId %></div>
        
        <div class="display-label">Age</div>
        <div class="display-field"><%: String.Format("{0:F}", Model.Age) %></div>
        
        <div class="display-label">Sex</div>
        <div class="display-field"><%: Model.Sex %></div>
        
    </fieldset>
    <table>
    <th>
    <td><div class="display-label">AddressLN1</div>
    </td>
    <td>
      <div class="display-label">AddressLN2</div>
    </td>
    <td>
      <div class="display-label">City</div>
      </td>
      <td>
       <div class="display-label">State</div>
      </td>
      <td>
      <div class="display-label">IsPrimary</div></td>
    </th>
    <%foreach (var add in Model.EmpAddresses)
      {
         %>
      <fieldset title="Employee Address">
        <legend>Employee Address</legend>
        
        <tr>
        <td> </td>
        <td>
        
        <div class="display-field"><%: add.AddressLN1%></div> </td>
        <td>
      
        <div class="display-field"><%: add.AddressLN2%></div> </td>
        <td>
      
        <div class="display-field"><%: add.City%></div> </td>
        <td>
       
        <div class="display-field"><%: add.State%></div> </td>
        <td>
        
        <div class="display-field"><%: add.IsPrimary%></div> </td>
       </tr>
    </fieldset>
    <%
        } %>
        </table>
         <table>
   <tr>
    <td> </td>
    <td>
      <div class="display-label">Basic Benfit</div>
      </td>
      <td>
       <div class="display-label">Flexi Benifit</div>
      </td>
      <td>
      <div class="display-label">Cost to Company</div></td>
      <td>
      <div class="display-label">Start Date</div></td>
      <td>
      <div class="display-label">End Date</div></td>
      <td> <div class="display-label">Employee Salary Split up </div></td>
    </tr>
    <%foreach (var Sal in Model.EmpBaseSals)
      {
         %>
      <fieldset title="Employee Address">
        <legend>Employee ANnual Salary </legend>
        
        <tr>
        <td> </td>
        <td>
        
        <div class="display-field"><%: Sal.TotalCTC%></div> </td>
        <td>
      
        <div class="display-field"><%: Sal.FLexiBenifit %></div> </td>
        <td>
      
        <div class="display-field"><%:(Sal.FLexiBenifit + Sal.TotalCTC)%></div> </td>
        
       <td>
      <div class="display-label"><%:  Sal.FromYear %></div></td>
      <td>
      <div class="display-label"><%:Sal.ToYear%></div></td>
       <td> 
       <table border="1" style="background-color:Silver ;color:Blue">
       <tr>
       <td>
       <b>basic</b>
       </td>
        <td>
     <b> HRA</b>
       </td>
         <td>
      <b>Bonus</b>
       </td>
       </tr>
       
   
       <%foreach (var SalD in Sal.EmpSalDetails)
      {
         %>
   
        
         <tr>
       
        <td>
        
        <div class="display-field"><%: SalD.Basic%></div> </td>
        <td>
      
        <div class="display-field"><%:  SalD.HRA %></div> </td>
        <td>
      
        <div class="display-field"><%:(SalD.Bonus )%></div> </td>
        </tr> 
       
    <%
        } %>
        </table></td></tr>
    </fieldset>
    <%
        } %>
        </table>
    <p>

        <%: Html.ActionLink("Clone", "Clone", new { id=Model.EMPID }) %> |
        <%: Html.ActionLink("CloneChild", "CloneChild", new { id=Model.EMPID }) %> |
        <%: Html.ActionLink("Back to List", "Index") %>
    </p>

</asp:Content>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

Appusamy.subbian
Software Developer (Senior)
India India
No Biography provided
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 8 May 2012
Article Copyright 2010 by Appusamy.subbian
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid