HI
I am using generic repository pattern for CRUD operations. I want to update the record and I am using the below code
public interface IRepository<TEntity> : IDisposable
{
List<TEntity> GetAll();
TEntity GetSinglEntity(Func<TEntity, bool> predicate);
bool Delete(TEntity entity);
bool Add(TEntity entity);
bool Update(TEntity entity);
} public class DataRepository<TEntity> : IRepository<TEntity> where TEntity : class
{
public bool Update(TEntity entity)
{
try
{
using (xrateEntities entities = new xrateEntities())
{
entities.Entry(entity).State = System.Data.Entity.EntityState.Modified;
// Below code is adding the new record
entities.Set<TEntity>().Add(entity); // How to update the entity or record
entities.SaveChanges();
return true;
// log here
}
}
catch (Exception exception)
{
// log here
throw exception;
}
return false;
}
}How to update the record using Entity framework?
Thanks