locked
Manage two models from procedure in web API RRS feed

  • Question

  • User-257070954 posted

    Hi all,

              In my stored procedure  i  am  returning two select statment and i am binding this to two models. now i want to show these two model as api result. How can i achieve this. 

    One set of data containg only one row of data and second set of data will have mutiple records

    expected result something like below

    {

     Country: "India"

    Profession: "Software"

    {

    "FirstName" : "ABC",

    "Lastname":"Def",

    },

    {

    "FirstName" : "PQR",

    "Lastname":"stu",

    },

    {

    "FirstName" : "Xyz",

    "Lastname":"hij",

    },

    }

    Wednesday, January 15, 2020 3:59 AM

All replies

  • User-1780421697 posted

    It could be like this

    {
      "country":"India",
      "profession": {
        "p1":"Business1",
        "p2":"Business2",
        "p3":"Business3"
      }
    }
    
    ---------------------------
    
    public class Profession
    {
        public string p1 { get; set; }
        public string p2 { get; set; }
        public string p3 { get; set; }
    }
    
    public class RootObject
    {
        public string country { get; set; }
        public Profession profession { get; set; }
    }

    Wednesday, January 15, 2020 5:31 AM
  • User-1780421697 posted
    {
      "country":"John",
      "profession": 
       {
        "professiondetail":{ name:""},
        "professiondetail":{name:""},
        "professiondetail":{name:""}
      }
     }
    
    --------------------------
    
    
    public class Professiondetail
    {
        public string name { get; set; }
    }
    
    public class Profession
    {
        public List<Professiondetail> professiondetail { get; set; }
    }
    
    public class RootObject
    {
        public string country { get; set; }
        public Profession profession { get; set; }
    }

    Wednesday, January 15, 2020 5:34 AM
  • User61956409 posted

    Hi binustrat,

    The example data you shared is not in valid JSON format, so we can not understand it better.

    If you'd like to include data set, like Engineer list, you can try to create a custom model class with expected properties based on your requirement, like below.

    public class CustomModel
    {
        public string Country { get; set; }
        public string Profession { get; set; }
    
        public List<Engineer> Engineers { get; set; }
    }
    
    public class Engineer
    {
        public string FirstName { get; set; }
        public string Lastname { get; set; }
    }

    With Regards,

    Fei Han

    Saturday, January 18, 2020 9:52 AM