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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:10:32+00:00 2026-06-10T00:10:32+00:00

I have a generic repository for my Entities, all my entities (generated by the

  • 0

I have a generic repository for my Entities, all my entities (generated by the Code generation Item) have a personalized partial that implements an IID interface, at this point all of my entites must have a Int32 Id property.

So, my problems is with the update, here is my code

public class RepositorioPersistencia<T> where T : class
{
    public static bool Update(T entity)
    {
        try
        {
            using (var ctx = new FisioKinectEntities())
            {
                // here a get the Entity from the actual context 
                var currentEntity = ctx.Set<T>().Find(((BLL.Interfaces.IID)entity).Id);

                var propertiesFromNewEntity = entity.GetType().GetProperties();
                var propertiesFromCurrentEntity = currentEntity.GetType().GetProperties();

                for (int i = 0; i < propertiesFromCurrentEntity.Length; i++)
                {
                    //I'am trying to update my current entity with the values of the new entity
                    //but this code causes an exception
                    propertiesFromCurrentEntity[i].SetValue(currentEntity, propertiesFromNewEntity[i].GetValue(entity, null), null);
                }
                ctx.SaveChanges();
                return true;
            }

        }
        catch
        {

            return false;
        }
    }
 }

Someone can help me? this driving me crazy.

  • 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-10T00:10:34+00:00Added an answer on June 10, 2026 at 12:10 am

    You can use the EF API to update the values of an entity as follows.

    public static bool Update(T entity)
    {
        try
        {
            using (var ctx = new FisioKinectEntities())
            {
                var currentEntity = ctx.Set<T>().Find(((BLL.Interfaces.IID)entity).Id);
    
                var entry = ctx.Entry(currentEntity);
                entry.CurrentValues.SetValues(entity);
    
                ctx.SaveChanges();
                return true;
            }
        }
        catch
        {
    
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created Generic Repository and I have two entities that i need to
I have a generic base repository class for LINQ-to-Entities that can do things like
I have a repository class that inherits from a generic implementation: public namespace RepositoryImplementation
I have a pretty generic repository that does basic CRUD for many of my
I am writing a generic repository to interface with EF using DBContext. I have
I created a generic repository that handles querying my entities. When I call this:
I have a generic repository that is using Entity Framework 4 with the DbContext
I have a generic repository that I use for common things such as FetchAllData,
I have a generic repository as like that public class Repository<T> : IRepository<T> where
I have the following generic method inside my class that works as a repository

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.