I have following code in my controller
[HttpGet]
public IHttpActionResult Get_User_Info(long id)
{
user u = new user();
List<user> lst = u.Get_userInfo(id);
if (lst.Count==0)
{
return NotFound();
}
else
return Ok(lst);
}
and my user class is
public class user : NK.Objects._user
{
public List<user> Get_userInfo(long userid)
{
address_city ac = new address_city();
string sql = "select id ,username ,cgroup ,regDate ,name ,picadr ,tell ,caddresscity ,resadress ,email from " + tbl_name + " where id=@id";
Q.dataaccesslayer.cmd.Parameters.Add("@id", System.Data.SqlDbType.BigInt).Value = userid;
List<user> lst = Q.Execute_List<user>(sql, this, new Queries.Cmd_Parameters(), 10);
lst.ForEach(t => t.resadress = ac.Get_City_Info(t.caddresscity) + " , " + t.resadress);
return lst;
}
}
user class inherits from following _ user class
public class _user
{
public static string tbl_name = "tbl_user";
public long id { get; set; }
public string username { get; set; }
public string password { get; set; }
public long cgroup { get; set; }
public string regDate { get; set; }
public string name { get; set; }
public string picadr { get; set; }
public string tell { get; set; }
public long caddresscity { get; set; }
public string resadress { get; set; }
public string email { get; set; }
}
the xml return is
<caddresscity xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</caddresscity>
<cgroup xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</cgroup>
<email xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</email>
<id xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</id>
<name xmlns="http://schemas.datacontract.org/2004/07/NK.Objects">1</name>
I think because of inheritance I am facing this problem and when I dont have inheritance it is working as expected.
How can I change the response to look as shown below:
<name>1</name>