locked
what is return type for the function RRS feed

  • Question

  • User-1722422105 posted

    Hi  all

    i have class like

    public class shopingmall
    {
    public List<shop_mall> smdata { get; set; }
    }
    public class shop_mall

    {
    public int sm_id { get; set; }
    public string sm_name { get; set; }
    public string sm_add { get; set; }

    public DateTime sm_opentime { get; set; }
    public DateTime sm_closetime { get; set; }

    public string sm_sm_desc { get; set; }

    }
    }

    i am geting the  shopingmall objmodel values from web api function like 

    public void Index()
    {

    testEntities objdemoentity = new testEntities();

    var studentercord = objdemoentity.sp_shopingmalldetails().ToList();

    shopingmall objmodel = new shopingmall();
    objmodel.smdata = new List<shop_mall>();

    objmodel.smdata = new List<shop_mall>();

    foreach (var item in studentercord.ToList())

    {


    objmodel.smdata.Add(new shop_mall { sm_name = item.sm_name, sm_add = item.sm_name });

    }

    }

    what is return type for geting the values

    Thursday, May 31, 2018 7:25 AM

All replies

  • User283571144 posted

    Hi sidu,

    what is return type for geting the values

    In my opinion, the return type is according to your design for the web api function.

    If you want to get the shopingmall obejct in the client side, I suggest you could return the shopingmall type.

    More details, you could refer to below test demo:

    Notice: I comment out the EF codes and directly add two shop_mall oject to shopingmall.

            public shopingmall Index()
            {
                //testEntities objdemoentity = new testEntities();
                //var studentercord = objdemoentity.sp_shopingmalldetails().ToList();
                shopingmall objmodel = new shopingmall();
                //objmodel.smdata = new List<shop_mall>();
                objmodel.smdata = new List<shop_mall>() {
                    new shop_mall(){ sm_id=1, sm_name="aaa" },
                    new shop_mall(){ sm_id=2, sm_name="bbb" },
                };
    
                //foreach (var item in studentercord.ToList())
                //{
    
                //    objmodel.smdata.Add(new shop_mall { sm_name = item.sm_name, sm_add = item.sm_name });
                //}
                return objmodel;
            }

    Result:

    Best Regards,

    Brando

    Friday, June 1, 2018 5:28 AM