csharpnoob
Member
- Joined
- Dec 22, 2022
- Messages
- 11
- Programming Experience
- Beginner
hi i started to learn EF6
last days
sorry if this not where to post
so the problem is the first query load always slow take like 5-15 sec
just trying to load combo box will take 5 sec
even if there is no data the load will be slow
why this happen and how to fix it
ClsCommander
ICommander
what i tried
LazyLoading set to false
using AsNoTracking
last days
sorry if this not where to post
so the problem is the first query load always slow take like 5-15 sec
just trying to load combo box will take 5 sec
even if there is no data the load will be slow
why this happen and how to fix it
C#:
public partial class Fpos : Form
{
public Fpos()
{
InitializeComponent();
}
ClsCommander<TBL_PRODUCT> CmdTblPRD = new ClsCommander<TBL_PRODUCT>();
TBL_PRODUCT TblPRD;
ClsCommander<TBL_PAY> CmdTblPayment = new ClsCommander<TBL_PAY>();
TBL_PAY TblPayment;
private void FillCmb()
{
CmbPAY.DataSource = CmdTblPayment.GetAll();
CmbPAY.ValueMember = nameof(TblPayment.ID);
CmbPAY.DisplayMember = nameof(TblPayment.PAY_DESC);
}
private void Fpos_Load(object sender, EventArgs e)
{
FillCmb();
}
}
ClsCommander
C#:
{
public class ClsCommander<TEntity> : ICommander<TEntity> where TEntity : class
{
DBWeSalesEntities Context = new DBWeSalesEntities();
public void Insert_Data(TEntity entity)
{
Context.Set<TEntity>().Add(entity);
Context.SaveChanges();
}
public void Update_Data(TEntity entity)
{
Context.Set<TEntity>().AddOrUpdate(entity);
Context.SaveChanges();
}
public void Delete_Data(TEntity entity)
{
Context.Set<TEntity>().Remove(entity);
Context.SaveChanges();
}
public IEnumerable<TEntity> GetAll()
{
return Context.Set<TEntity>().ToList();
}
public IEnumerable<TEntity> GetBy(Expression<Func<TEntity, bool>> P)
{
return Context.Set<TEntity>().Where(P);
}
public IEnumerable<TEntity> MaxID(Expression<Func<TEntity, bool>> P)
{
return Context.Set<TEntity>().Where(P);
}
}
ICommander
C#:
interface ICommander<TEntity>
{
// inserting data
void Insert_Data(TEntity entity);
// updating data
void Update_Data(TEntity entity);
// delete data
void Delete_Data(TEntity entity);
// get all data tolist
IEnumerable<TEntity> GetAll();
// get by
IEnumerable<TEntity> GetBy(Expression<Func<TEntity , bool>> P);
// max
IEnumerable<TEntity> MaxID(Expression<Func<TEntity, bool>> P);
}
LazyLoading set to false
using AsNoTracking
Last edited: