Hello everybody:
i'm trying to execute a stored procedure in my app , i'm using (Module Zero) but i facing issue with (Create Query & Session)
Here is my code
public interface IEmpRepository : IRepository<Employee>
{
List<Employee> GetAllWithDepartment(int? deptID);
}
public class EmpRepository : EmployeesTasksRepositoryBase<Employee, int>, IEmpRepository
{
public EmpRepository(IDbContextProvider<EmployeesTasksDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public List<Employee> GetAllWithDepartment(int? deptID)
{
var query = Abp.Runtime.Session
.CreateQuery("spGetEmployeesWithUsersWithDepartments")
.SetParameter("deptId", deptID);
}
}
Thank you all;
4 Answer(s)
-
0
Thank you
I use this:
public IEnumerable<Employee> GetAllWithDepartment(int? deptID) { var departmentIDParameter = deptID != null ? new SqlParameter("@dept_id", deptID) : new SqlParameter("@dept_id", typeof (int)); return Context.Database.SqlQuery<Employee>("spGetEmployeesWithUsersWithDepartments @dept_id", departmentIDParameter); }
-
0
Hello All;
My Project structure like this
- MyProject.Core
- MyProject.App
- MyProject.EF [list:20feq927][:20feq927]EmpRepository (Stored procedure here as above implementation)[/:m:20feq927] [:20feq927]MyProject.Test[/:m:20feq927][/list:u:20feq927]
In my test app
private readonly IEmpRepository _EmpRepository; //Constructor public UnitTestClass() { _EmpRepository = LocalIocManager.Resolve<IEmpRepository>(); } [TestMethod] public void Should_Add_Employee_With_Authorized_User() { var result = _EmpRepository.GetAllWithDepartment(1); result.Count().ShouldBe(100); }
- I got exception:"The operation cannot be completed because the DbContext has been disposed".
- Is that the appropriate way to use this (like ref --MyProject.EF -- into --MyProject.Test--).
Thank you :)
-
0
Hi,
Have you checked this article: <a class="postlink" href="http://www.codeproject.com/Articles/871786/Unit-testing-in-Csharp-using-xUnit-Entity-Framewor">http://www.codeproject.com/Articles/871 ... y-Framewor</a>
This article does not cover SPs but can give an idea of testing apps with ABP.
Are you trying to run tests against an actual database? It's not a suggested way generally since it may be changed and your tests will not be consistent. You can setup and use local DB for unit tests, I did it before, it's slow but covers SPs.