Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public List<personmodel> GetPerson_All()
{
List<personmodel> output ;

using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments")))
{
  output = connection.Query<personmodel>("dbo.spPeopleNew_GetAll").ToList();
}
return output;
}


What I have tried:

When I try to debug the project, I realized that the output has 5 items, which is true according to my sample data. I have 5 people in the DB. But it only returns the Id field correctly. And null for other fields.
I can't figure out why. The stored procedure code is below and it works fine at the ms sql side when I exec it separately.

SQL
ALTER PROCEDURE [dbo].[spPeopleNew_GetAll]
AS
SET NOCOUNT ON
    -- Insert statements for procedure here
	SELECT *
	from dbo.tblPeopleNew 
Posted
Updated 24-Oct-19 14:24pm
v3

1 solution

Assuming that the tblPeopleNew table has more than the one column; the problem most likely is in the ORM that is mapping the SQL result set to your model. Are the columns being returned of the same name and type as the properties of your model?
 
Share this answer
 
Comments
Tim Corey 24-Oct-19 22:58pm    
I agree. If your table has a column called First_Name but your property in your model is firstname, it will not link the two. Make sure the spelling matches exactly.
Cetin OGUT 25-Oct-19 2:13am    
Many thanks. I missed the point about mapping. When I updated the table column names to the same as PersonModal property names, it worked accordingly. Now I can continue with the tutorial...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900