Last active
August 29, 2015 14:10
-
-
Save ycaroafonso/a87ab4e3a59ec4b69467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <summary> | |
| /// Por: Ycaro Afonso | |
| /// Data: 20/08/2014 | |
| /// | |
| /// Atualiza apenas os parametros informados de uma tabela. | |
| /// Exemplo: Tabela Pessoa, atualizar apenas Nome e Idade | |
| /// | |
| /// UpdateParametro(Contexto, instancia | |
| /// , c => c.Nome | |
| /// , c => c.Idade) | |
| /// .SaveChanges(); | |
| /// </summary> | |
| /// <typeparam name="TContexto"></typeparam> | |
| /// <typeparam name="TEntity"></typeparam> | |
| /// <param name="contexto"></param> | |
| /// <param name="instancia"></param> | |
| /// <param name="parametrosAtualizar"></param> | |
| /// <returns></returns> | |
| public TContexto UpdateParametro<TContexto, TEntity>(TContexto contexto, TEntity instancia | |
| , params Expression<Func<TEntity, object>>[] parametrosAtualizar) | |
| where TContexto : DbContext | |
| where TEntity : class | |
| { | |
| contexto.Set<TEntity>().Attach(instancia); | |
| contexto.Entry(instancia).State = EntityState.Unchanged; | |
| foreach (var expression in parametrosAtualizar) | |
| { | |
| Contexto.Entry(instancia).Property(expression).IsModified = true; | |
| } | |
| return contexto; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment