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;








0















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.










share|improve this question
























  • 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

















0















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.










share|improve this question
























  • 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













0












0








0








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.










share|improve this question
















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 sql-server dapper






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












1 Answer
1






active

oldest

votes


















0














 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();







share|improve this answer























    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
    );



    );













    draft saved

    draft discarded


















    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









    0














     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();







    share|improve this answer



























      0














       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();







      share|improve this answer

























        0












        0








        0







         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();







        share|improve this answer













         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();








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 5:56









        ITQAITQA

        1166




        1166





























            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?