【问题标题】:Pass from Model to BLL to DAL从模型传递到 BLL 到 DAL
【发布时间】:2020-06-19 15:05:37
【问题描述】:

我在模型中有这个类

   public class AssignStudentDetails
   {
     public string StudentName { get; set; }
     public string TeacherName { get; set; }
   }

这是我的 BLL 层,我想将 Addstudentdetails 添加到列表中,然后将其传递给 DAL 层

   public void AddStudentsList(AssignStudentDetails AddStudentDetails) 
   {
      //code how to add addstudentdetails and pass to DAL 
   }


    public void AddStudentDAL(//what i have to pass here?)
    { 
      //my sql connection i will write here
    }

请告诉我怎么做

【问题讨论】:

  • 您能澄清一下您的问题吗?你想达到什么目标,到目前为止你遇到了什么问题?
  • 我已经编写了用于插入学生姓名和教师姓名的 SQL 连接,现在我想将数据从 Assignstudent 详细信息类传递到 BLL 层,从 BLL 到 DAL 函数我必须传递值

标签: c# asp.net-mvc model-view-controller


【解决方案1】:

在 BLL 中将方法返回类型从 void 更改为 AssignStudentDetails:

public AssignStudentDetails AddStudentsList(AssignStudentDetails AddStudentDetails) 
{
  //code how to add addstudentdetails and pass to DAL 
  AssignStudentDetails assgnStdDet = new AssignStudentDetails ()
  {
     AssignStudentDetailsProperty = AddStudentDetails.CorrespondingProperty
     //rest of properties
  }
  return assgnStdDet; 
}

然后在DAL中调用BLL方法:

public void AddStudentDAL(AssignStudentDetails AddStudentDetails)
{ 
  //my sql connection i will write here
  AssignStudentDetails assgnStdDet = AddStudentsList(AddStudentDetails);
  YourDBContext.AssignStudentDetailsDBSet.Add(assgnStdDet);
  YourDBContext.SaveChanges();
}

【讨论】:

    猜你喜欢
    • 2012-03-04
    • 2010-10-17
    • 2015-05-13
    • 1970-01-01
    • 2017-09-28
    • 2020-08-31
    • 1970-01-01
    • 2017-08-05
    • 2013-03-13
    相关资源
    最近更新 更多