EF Code First Calling Stored Procedures with Complex Return Type

I have a SP that returns list of Employees and a single row Department which should be consumed from EF code first.

I have the below object that needs to be filled,

public class EmployeeDetail
{
public IList<Employee> employeeslist { get;set; }
public int DeptID { get;set; }
public string DepartmentName { get;set; }
public int DeptStatusID { get;set; }
public decimal Expense  { get;set; }
}

public partial class DBModel : DbContext
 {
    public ObjectResult<EmployeeDetail> PaymentBatchDetailsGet(int deptid)
      {
       return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<EmployeeDetail>
                        ("GetEmployees @p0", deptid);
      }
 }

The SP is very simple which has 2 simple query listed below,

select * from Employee where DepartmentID = @deptid
select DepartmentName,DeptStatusID,Expense 
FROM Department where DepartmentID = @deptid

All the properties in EmployeeDetail class is getting populated except employeeslist. Could you please help?

Answers


What makes you think that would work? As I understand it, the ExecuteStoreQuery method will only populate properties with primitive types (numbers, strings, etc.). See https://msdn.microsoft.com/en-us/library/ee358758(v=vs.110).aspx

Also, I'm not sure why you think it would work when the results are returned in two recordsets.

I'd love to think that this sort of thing could work, but I think it would be surprising if it did.

I think you'll need to split your SP into two parts, one that gets the top-level info, and another that gets the employees.


Need Your Help

What is the maximum texture size available on the iPad?

ipad textures opengl-es-2.0

Anyone know the maximum texture size for the iPad? I'm having trouble finding numbers for this.

Iframe Errors Ahoy

javascript html iframe

The following iframe is designed to fit to it's content. It works in Firefox, but not in Chrome.