Problem returning properties to Class list from SQL queryHow to return only the Date from a SQL Server DateTime datatypeHow to concatenate text from multiple rows into a single text string in SQL server?SQL update from one Table to another based on a ID matchInserting multiple rows in a single SQL query?How to get the list of properties of a class?SQL update query using joinsHow do I UPDATE from a SELECT in SQL Server?How to Sort a List<T> by a property in the objectManually map column names with class propertiesWhy not inherit from List<T>?
Could a 19.25mm revolver actually exist?
Installed Electric Tankless Water Heater - Internet loss when active
How to use " shadow " in pstricks?
Employer demanding to see degree after poor code review
What is quasi-aromaticity?
Were pens caps holes designed to prevent death by suffocation if swallowed?
Can I tell a prospective employee that everyone in the team is leaving?
My employer faked my resume to acquire projects
How can I tell if I'm being too picky as a referee?
Line of lights moving in a straight line , with a few following
What to do when you've set the wrong ISO for your film?
How to illustrate the Mean Value theorem?
Have 1.5% of all nuclear reactors ever built melted down?
Would Brexit have gone ahead by now if Gina Miller had not forced the Government to involve Parliament?
Who will lead the country until there is a new Tory leader?
Why are values I enter in the interface getting halved?
How did these characters "suit up" so quickly?
Website returning plaintext password
Crossing US border with music files I'm legally allowed to possess
Where have Brexit voters gone?
Is the Indo-European language family made up?
Is there an online tool which supports shared writing?
Where's this lookout in Nova Scotia?
Would jet fuel for an F-16 or F-35 be producible during WW2?
Problem returning properties to Class list from SQL query
How to return only the Date from a SQL Server DateTime datatypeHow to concatenate text from multiple rows into a single text string in SQL server?SQL update from one Table to another based on a ID matchInserting multiple rows in a single SQL query?How to get the list of properties of a class?SQL update query using joinsHow do I UPDATE from a SELECT in SQL Server?How to Sort a List<T> by a property in the objectManually map column names with class propertiesWhy not inherit from List<T>?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am try to query a SQL server using Dapper and get it to return a list of class objects with the column values as the matching properties for each object. I have a class called LeaveInfo with the following properties:
ID, Name, Date_, Leave, TDY, Appointments, Unavailable
and a SQL Table with matching columns, except Name. My code for the query is:
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave @ID, @Date_",
new ID = id, Date_ = date ).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
SQL Procedure being called:
Create Procedure LeaveCalendar_GetLeave
@ID VARCHAR(2),
@Date_ Date
As
Begin
Set NoCount on
Select * from LeaveCalendar
Where ID = @ID and Date_ = @Date_
End
Instead of returning all of the columns it only returns ID and Date_.
The commented out code are two similar queries that do the same thing and work exactly right, returning all property values of their respective classes.
I have queried it manually in SQL server
Select * from LeaveCalendar
Where ID = 54 and Date_ = '20191011'
for instance..
and it works fine there. So I have two other queries that work and as far as I can tell no errors with the SQL portion. I am not sure where the disconnect is occurring at this point.
I checked the property names to make sure they are aligning with the column names. Not only do they, but I have two procedures to add and delete information, to the same table using the same values, that also work.
So I can add and delete information just not check it from within the application...
Edit:
Apologies for the late additions and thank you for the time you all took to help. Unfortunately I found a syntax error elsewhere that resolved my issues, it's a wonder what fresh eyes will do for you...
It doesn't seem I can delete my question despite the trivial root cause.
c# sql
add a comment |
I am try to query a SQL server using Dapper and get it to return a list of class objects with the column values as the matching properties for each object. I have a class called LeaveInfo with the following properties:
ID, Name, Date_, Leave, TDY, Appointments, Unavailable
and a SQL Table with matching columns, except Name. My code for the query is:
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave @ID, @Date_",
new ID = id, Date_ = date ).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
SQL Procedure being called:
Create Procedure LeaveCalendar_GetLeave
@ID VARCHAR(2),
@Date_ Date
As
Begin
Set NoCount on
Select * from LeaveCalendar
Where ID = @ID and Date_ = @Date_
End
Instead of returning all of the columns it only returns ID and Date_.
The commented out code are two similar queries that do the same thing and work exactly right, returning all property values of their respective classes.
I have queried it manually in SQL server
Select * from LeaveCalendar
Where ID = 54 and Date_ = '20191011'
for instance..
and it works fine there. So I have two other queries that work and as far as I can tell no errors with the SQL portion. I am not sure where the disconnect is occurring at this point.
I checked the property names to make sure they are aligning with the column names. Not only do they, but I have two procedures to add and delete information, to the same table using the same values, that also work.
So I can add and delete information just not check it from within the application...
Edit:
Apologies for the late additions and thank you for the time you all took to help. Unfortunately I found a syntax error elsewhere that resolved my issues, it's a wonder what fresh eyes will do for you...
It doesn't seem I can delete my question despite the trivial root cause.
c# sql
You can use dynamic as well.
– ITQA
Mar 24 at 5:50
Please show us your model class and the attributes in your database table. The disconnect might behappening because of incorrect mapping between your class properties and column names.
– Rahul Sharma
Mar 24 at 6:35
add a comment |
I am try to query a SQL server using Dapper and get it to return a list of class objects with the column values as the matching properties for each object. I have a class called LeaveInfo with the following properties:
ID, Name, Date_, Leave, TDY, Appointments, Unavailable
and a SQL Table with matching columns, except Name. My code for the query is:
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave @ID, @Date_",
new ID = id, Date_ = date ).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
SQL Procedure being called:
Create Procedure LeaveCalendar_GetLeave
@ID VARCHAR(2),
@Date_ Date
As
Begin
Set NoCount on
Select * from LeaveCalendar
Where ID = @ID and Date_ = @Date_
End
Instead of returning all of the columns it only returns ID and Date_.
The commented out code are two similar queries that do the same thing and work exactly right, returning all property values of their respective classes.
I have queried it manually in SQL server
Select * from LeaveCalendar
Where ID = 54 and Date_ = '20191011'
for instance..
and it works fine there. So I have two other queries that work and as far as I can tell no errors with the SQL portion. I am not sure where the disconnect is occurring at this point.
I checked the property names to make sure they are aligning with the column names. Not only do they, but I have two procedures to add and delete information, to the same table using the same values, that also work.
So I can add and delete information just not check it from within the application...
Edit:
Apologies for the late additions and thank you for the time you all took to help. Unfortunately I found a syntax error elsewhere that resolved my issues, it's a wonder what fresh eyes will do for you...
It doesn't seem I can delete my question despite the trivial root cause.
c# sql
I am try to query a SQL server using Dapper and get it to return a list of class objects with the column values as the matching properties for each object. I have a class called LeaveInfo with the following properties:
ID, Name, Date_, Leave, TDY, Appointments, Unavailable
and a SQL Table with matching columns, except Name. My code for the query is:
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave @ID, @Date_",
new ID = id, Date_ = date ).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
SQL Procedure being called:
Create Procedure LeaveCalendar_GetLeave
@ID VARCHAR(2),
@Date_ Date
As
Begin
Set NoCount on
Select * from LeaveCalendar
Where ID = @ID and Date_ = @Date_
End
Instead of returning all of the columns it only returns ID and Date_.
The commented out code are two similar queries that do the same thing and work exactly right, returning all property values of their respective classes.
I have queried it manually in SQL server
Select * from LeaveCalendar
Where ID = 54 and Date_ = '20191011'
for instance..
and it works fine there. So I have two other queries that work and as far as I can tell no errors with the SQL portion. I am not sure where the disconnect is occurring at this point.
I checked the property names to make sure they are aligning with the column names. Not only do they, but I have two procedures to add and delete information, to the same table using the same values, that also work.
So I can add and delete information just not check it from within the application...
Edit:
Apologies for the late additions and thank you for the time you all took to help. Unfortunately I found a syntax error elsewhere that resolved my issues, it's a wonder what fresh eyes will do for you...
It doesn't seem I can delete my question despite the trivial root cause.
c# sql
c# sql
edited Mar 26 at 1:51
v07
asked Mar 24 at 5:33
v07v07
12
12
You can use dynamic as well.
– ITQA
Mar 24 at 5:50
Please show us your model class and the attributes in your database table. The disconnect might behappening because of incorrect mapping between your class properties and column names.
– Rahul Sharma
Mar 24 at 6:35
add a comment |
You can use dynamic as well.
– ITQA
Mar 24 at 5:50
Please show us your model class and the attributes in your database table. The disconnect might behappening because of incorrect mapping between your class properties and column names.
– Rahul Sharma
Mar 24 at 6:35
You can use dynamic as well.
– ITQA
Mar 24 at 5:50
You can use dynamic as well.
– ITQA
Mar 24 at 5:50
Please show us your model class and the attributes in your database table. The disconnect might behappening because of incorrect mapping between your class properties and column names.
– Rahul Sharma
Mar 24 at 6:35
Please show us your model class and the attributes in your database table. The disconnect might behappening because of incorrect mapping between your class properties and column names.
– Rahul Sharma
Mar 24 at 6:35
add a comment |
1 Answer
1
active
oldest
votes
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
var param = new DynamicParameters();
param.Add("@ID", id, DbType.String, ParameterDirection.Input);
param.Add("@Date_", date, DbType.String, ParameterDirection.Input);
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave", param, commandType: CommandType.StoredProcedure).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321008%2fproblem-returning-properties-to-class-list-from-sql-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
var param = new DynamicParameters();
param.Add("@ID", id, DbType.String, ParameterDirection.Input);
param.Add("@Date_", date, DbType.String, ParameterDirection.Input);
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave", param, commandType: CommandType.StoredProcedure).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
add a comment |
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
var param = new DynamicParameters();
param.Add("@ID", id, DbType.String, ParameterDirection.Input);
param.Add("@Date_", date, DbType.String, ParameterDirection.Input);
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave", param, commandType: CommandType.StoredProcedure).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
add a comment |
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
var param = new DynamicParameters();
param.Add("@ID", id, DbType.String, ParameterDirection.Input);
param.Add("@Date_", date, DbType.String, ParameterDirection.Input);
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave", param, commandType: CommandType.StoredProcedure).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
public List<LeaveInfo> getLeaveInfo(string id, string date)
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.ConnectStr("Schedules")))
var param = new DynamicParameters();
param.Add("@ID", id, DbType.String, ParameterDirection.Input);
param.Add("@Date_", date, DbType.String, ParameterDirection.Input);
return connection.Query<LeaveInfo>("dbo.LeaveCalendar_GetLeave", param, commandType: CommandType.StoredProcedure).ToList();
//return connection.Query<Person>("dbo.Personnel_GetShift @Shift_", new Shift_ = shift_ ).ToList();
//return connection.Query<Truck>("dbo.Trucks_GetTrucks").ToList();
answered Mar 24 at 5:56
ITQAITQA
1166
1166
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55321008%2fproblem-returning-properties-to-class-list-from-sql-query%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You can use dynamic as well.
– ITQA
Mar 24 at 5:50
Please show us your model class and the attributes in your database table. The disconnect might behappening because of incorrect mapping between your class properties and column names.
– Rahul Sharma
Mar 24 at 6:35