mardi 29 mars 2016

How to access a method in the context through unit of work?

If I have the following Context :

 public partial class HRMainDataCTX : DbContext
    {
        public HRMainDataCTX()
            : base("name=HRMainDataCTX")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

      //DbSets
        public virtual int SEARCHEMPLOYEE(Nullable<decimal> p_EMP_NUM, string p_EMP_NAME)
        {
            var p_EMP_NUMParameter = p_EMP_NUM.HasValue ?
                new ObjectParameter("P_EMP_NUM", p_EMP_NUM) :
                new ObjectParameter("P_EMP_NUM", typeof(decimal));

            var p_EMP_NAMEParameter = p_EMP_NAME != null ?
                new ObjectParameter("P_EMP_NAME", p_EMP_NAME) :
                new ObjectParameter("P_EMP_NAME", typeof(string));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SEARCHEMPLOYEE", p_EMP_NUMParameter, p_EMP_NAMEParameter);
        }
    }

Now i implement Unit of work like this :

public class HRCTX : IDisposable
    {
        private readonly HRMainDataCTX _context;

        public HRCTX()
        {
            _context = new HRMainDataCTX();
        }

        public HRCTX(HRMainDataCTX context)
        {
            _context = context;
        }
        public int Save()
        {
            return _context.SaveChanges();
        }

        public HRMainDataCTX Context
        {
            get { return _context; }
        }

        public void Dispose()
        {
            _context.Dispose();
        }
    }


I don't know how to access the method (stored procedure) SEARCHEMPLOYEE through UOW in my code behind.

Aucun commentaire:

Enregistrer un commentaire