4
I’m making a simple insert
of a user class, it is taking almost 10 seconds to record the information. So I tried to find other solutions to solve my performance problem and found the Dapper
.
My doubt there is some way to use both ORMs
in my project? because I liked the EF in the question of mapping and Migrations because I use as Code First.
To reach this conclusion of slowness I used this article as a theoretical reference.
The classes I’m using:
User:
[Table("Usuario", Schema = "public")]
public class Usuario : PessoaBase
{
private string login;
private string senha;
public Usuario(string nome, string email, int status, string login, string senha, DateTime dtCriacao) : base( nome, status, dtCriacao, email)
{
this.login = login;
this.senha = senha;
}
[DisplayName("Login")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Login deve ser preenchido!")]
[StringLength(50)]
[Index("Ix_UsuarioLogin", IsUnique = true)]
public string Login
{
get { return login; }
set { login = value; }
}
[DisplayName("Senha")]
[Required(AllowEmptyStrings = false, ErrorMessage = "Senha deve ser preechida!")]
[StringLength(20)]
public string Senha
{
get { return senha; }
set { senha = value; }
}
}
Repository:
public abstract class Repositorio<TEntity> : IDisposable,
IRepositorio<TEntity> where TEntity : class
{
BaseContexto ctx = new BaseContexto();
public IQueryable<TEntity> GetAll()
{
return ctx.Set<TEntity>();
}
public IQueryable<TEntity> Get(Func<TEntity, bool> predicate)
{
return GetAll().Where(predicate).AsQueryable();
}
public TEntity Find(params object[] key)
{
return ctx.Set<TEntity>().Find(key);
}
public void Atualizar(TEntity obj)
{
ctx.Entry(obj).State = EntityState.Modified;
}
public void SalvarTodos()
{
ctx.SaveChanges();
}
public void Adicionar(TEntity obj)
{
ctx.Set<TEntity>().Add(obj);
}
public void Excluir(Func<TEntity, bool> predicate)
{
ctx.Set<TEntity>()
.Where(predicate).ToList()
.ForEach(del => ctx.Set<TEntity>().Remove(del));
}
public void Dispose()
{
ctx.Dispose();
}
}
To save a user just do it this way:
uDal.Adicionar(u);
uDal.SalvarTodos();
OBS: I’m using Netframework 4.5, visual studio 2013 and BD postgresql.
The main thing would be to identify the slowness, the Entity Framework is not to be so slow 10 seconds is a lot, must have problems as it is in the programming, on the repository layer already have problems as you did, because for each item will have a different context, this is a problem many do, has to be done a little differently, and some developers are against, but, I see in your question that the problem is bigger, think 10 seconds is too long. Take a look at your project in the background, just a hint.
– novic
One more thing I use EF in my projects and have no problem at the time of recording or even recovery that is more expensive, works very well inclusive.
– novic