3

Good day!

I am having a hard time returning data collection with existing data (SQL Server 2012) on .Net Core ADO.NET Entity Model. Also, it does not step through breakpoint on my Ienumerable<>Get() but the breakpoint crosses through public string Get(int id). How is it possible to cross through breakpoint on IEnumerable? I also tried following this link Cannot step into a method returning IEnumerable<T>? , adding ".ToList()" on my code but it still does not cross on breakpoint. :( I have no error on my code.

Here is my code :

My ADO.NET Entity Model

namespace EmployeeDataAccess
{
    using System;
    using System.Collections.Generic;

    public partial class tbl_employee
    {
        public long emp_id { get; set; }
        public Nullable<long> group_id { get; set; }
        public Nullable<long> company_id { get; set; }
        public Nullable<long> RC_id { get; set; }
        public string emp_globalno { get; set; }
        public string emp_siteno { get; set; }
        public string emp_prefix { get; set; }
        public string emp_lastname { get; set; }
        public string emp_firstname { get; set; }
        public string emp_middlename { get; set; }
        public string emp_suffix { get; set; }
    }
}

enter image description here

My IEnumerable code (does not cross on breakpoint):

// GET api/values
[HttpGet]
    public IEnumerable<tbl_employee> Get()
    {
        List<EmployeeEntities> EmployeesList = new List<EmployeeEntities>();
        var empTable = new tbl_employee();
        var temp = empTable.emp_firstname.ToString();

        var employeelist = (from Employees in EmployeesList 
                            select new tbl_employee
                            { emp_firstname = empTable.emp_firstname }).ToList();
        return employeelist;


    }

Screenshot on trying to return IEnumerable :

enter image description here

My Get(id) code (crosses on breakpoint) :

// GET api/values/5
[HttpGet("{id}")]
public string Get(int id)
{
    return "value 1, value 2, value 3";
}

Screenshot on returning Get(ID) :

enter image description here

Will gladly appreciate any suggestions, comments, replies.

Thank you very much and have a nice day!

(UPDATE)

I tried reverting to the default static IEnumerable<>Get() and it crosses the breakpoint and returns json values. How do I do this with returning existing data on SQL Server 2012 db using ADO.NET? Thanks.

The default code I reverted back :

[HttpGet]
public IEnumerable<string> Get()
{
    return new string[] { "value1", "value2", "value3" };
}

Screenshot on the result :

enter image description here

3
  • What does your WebApiConfig.cs look like? Since you have multiple HTTP GET requests in your API, you might need to modify your Routes - see this answer to the question Single controller with multiple GET methods in ASP.NET Web API. Commented Sep 8, 2017 at 3:22
  • hi sir @Poosh! first of all thank you for your response. I tried adding the routes but it's still the same :( Also, I tried reverting to the default static IEnumerable and it crosses the breakpoint now and returns a result. How do I do this in returning existing data on my SQL Server database? Thanks Sir! Commented Sep 8, 2017 at 3:49
  • trying throwing exception in Get() function and see what happens. Also clean solution and then try running it. It should return null as you should not have anything in EmployeeList list. Commented Sep 14, 2017 at 4:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.