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

The Archive Base Latest Questions

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

I use the .NET Entity Framework. I want to copy properties from one EntityObject

  • 0

I use the .NET Entity Framework. I want to copy properties from one EntityObject to another. But System.Type.GetProperties() does not seem to return the properties defined on the partial class.

Code:

In XXX.edmx/ XXX.Designer.cs generated by Visual Studio, I have class MyTable:

public partial class MyTable: EntityObject{..}

I want to add some properties to MyTable class, so I add file XXX.Manual.cs:

public partial class MyTable: EntityObject{
    public string myProp{get;set;}
}

But myTableObj.GetType().GetProperties() does not contain myProp!!!

How can I get myProp using reflection?

[EDIT] I want to comment to Alex answer but don’t know why the code section is not formated.

Yes, this is very strange.
I use this code to copy properties from Entity to another obj:

public static void CopyTo(this EntityObject Entity, EntityObject another){
    var Type = Entity.GetType();
    foreach (var Property in Type.GetProperties()){
        ...
        Property.SetValue(another, Property.GetValue(Entity, null), null);
    }
}
//in some other place:
myTableObj.CopyTo(anotherTableObj);

Of couse myTableObj & anotherTableObj is of type MyTable.

When debug into the CopyTo method, VS show that Entity & another is of type MyTable & I can see Entity.myProp, another.myProp

But the Property var in foreach statement simply don’t loop to myProp property!

[EDIT] Sorry. The code above (CopyTo method) is copy from diamandiev’s answer for another question

But his code is wrong: The “break” statement must be replace by “continue” 😀

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

    First of all partial classes is just how source code is split. It does not affect the compiled assembly.

    It is likely that you don’t see myProp property because myTableObj is not of type MyTable.

    Try this:

    var property = typeof(MyTable).GetProperty("myProp");
    

    [EDIT]

    Just checked:

    EntityObject x = new MyTable();
    
    var property1 = typeof(MyTable).GetProperty("myProp");
    var property2 = x.GetType().GetProperty("myProp");
    

    Both property1 and property2 returned the property.

    [EDIT]

    Tried your code, it worked after small modification:

    public static void CopyTo(EntityObject fromEntity, EntityObject toEntity)
    {
        foreach (var property in fromEntity.GetType().GetProperties())
        {
            if (property.GetSetMethod() == null)
                continue;
            var value = property.GetValue(fromEntity, null);
            property.SetValue(toEntity, value, null);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very confused with the use subsonic or ado.net entity framework Which one
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity
Can I use two different back ends for an .net Entity Framework project? I
How do I use Datatable instead of Entity framework in Asp.Net mvc? I'm referring
For my ASP.NET MVC 2 application I use Entity Framework 1.0 as my data
With .NET, which data access method is better to use LINQ to SQL,entity framework,
If I use ADO.NET Entity Framework in our project and we depend on a
I am using ASP.NET MVC 3 with Entity Framework 4 using POCOs and want
I have created an asp.net application using Entity Framework. In this I want to
I installed a lot of ado.net entity framework versions and tools. one of them

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.