Resolved Performance Issue

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


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);
    }
what i tried
LazyLoading set to false
using AsNoTracking
 
Last edited:
I suspect you are the victim of multiple rebinds.
See the tip in post #2:
and the explanation why in post #6:
 
Moved to Entity Framework.

What is your backend database?

Is the combobox load the first database query for the entire application? If so, Entity Framework needs to do the initial connection to the database and setting up of all its infrastructure.

Given that, I do agree that 5-15 seconds feels excessively slow. What does the profiler show as being the time sink?
 
hi Sorry for wasting ur time .

database : MSSQL


i just did a lot of thing in last hours .

the load time now like 4sec . better then before ( only first query feel slow then everything will be fine)

here is code : Re: sssssssss - Pastebin ( I'm just learning . any tips thanks )

what i did :
LazyLoading set to false

Capture.JPG


any tips thanks .
sorry for my english . thanks for ur time
 
hi thanks cjard sorry for late replay was stuck with something else. about the timing i was looking at the time in panel . when i click btn the whole form freeze for 5 sec .
use same code but with stored query there was no prblems . anyway i just deleted the project and started with another one and the performance is better dont knew why didnt get any performance issue like last one .
 
Back
Top Bottom