非静态方法需要目标实体框架

时间:2018-12-17 07:38:00

标签: c# entity-framework api web

我遇到错误“非静态方法需要目标”。当我执行此代码。我是Api的初学者。这将是一个很大的帮助。

     public object StudentReg(tblreg reg)
     {
         try
         {
             var q = db.tblregs.FirstOrDefault(x => x.Email == reg.Email && x.Contact == reg.Contact);

             if (q == null)
             {
                 reg.Name = reg.Name;
                 reg.Email = reg.Email;
                 reg.Contact = reg.Contact;
                 reg.Passwod = reg.Passwod;
                 reg.IsApproved = reg.IsApproved;
                 reg.Crdt = DateTime.Now;
                 reg.Updt = null;
                 reg.Stat = true;
                 db.tblregs.Add(reg);
                 db.SaveChanges();

                 return new { result = "Employee Registration Successful" };
             }
             else
             {
                 return new { result = "This Employee already exists" };
             }
         }
         catch (Exception ex)
         {
             return new { error = ex.Message };

         }
    }

0 个答案:

没有答案