How to use SQL Joins in Web API





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I need to pass SQL Query(with Joins) as parameter to my API and retrun the results. But the result is dependent on the using the below code. I there any way to get this fixed. Please advise.



Expected results should be all the columns from the query into var users variable.



public IHttpActionResult retData()
{
using (var context = new DBModel())
{
var users = context.Database.SqlQuery<portal_testcase_scn>("SELECT *,Portal_Version.build FROM [portal_testcase_scn] inner join Portal_Version on [portal_testcase_scn].row_num=Portal_Version.row_num").ToList();
return Ok(users);
}
}









share|improve this question

























  • Hi, what problem do you have?

    – Backs
    Jan 3 at 3:23











  • I am retrieving data from portal_testcase_scn and Portal_Version table using joins. But API is returning data from portal_testcase_scn. Because I have mentioned portal_testcase_scn as datatype within SqlQuery<>. Is there a way to get all teh columsn from both the tables in API?

    – Shreyas Murali
    Jan 3 at 3:48


















0















I need to pass SQL Query(with Joins) as parameter to my API and retrun the results. But the result is dependent on the using the below code. I there any way to get this fixed. Please advise.



Expected results should be all the columns from the query into var users variable.



public IHttpActionResult retData()
{
using (var context = new DBModel())
{
var users = context.Database.SqlQuery<portal_testcase_scn>("SELECT *,Portal_Version.build FROM [portal_testcase_scn] inner join Portal_Version on [portal_testcase_scn].row_num=Portal_Version.row_num").ToList();
return Ok(users);
}
}









share|improve this question

























  • Hi, what problem do you have?

    – Backs
    Jan 3 at 3:23











  • I am retrieving data from portal_testcase_scn and Portal_Version table using joins. But API is returning data from portal_testcase_scn. Because I have mentioned portal_testcase_scn as datatype within SqlQuery<>. Is there a way to get all teh columsn from both the tables in API?

    – Shreyas Murali
    Jan 3 at 3:48














0












0








0








I need to pass SQL Query(with Joins) as parameter to my API and retrun the results. But the result is dependent on the using the below code. I there any way to get this fixed. Please advise.



Expected results should be all the columns from the query into var users variable.



public IHttpActionResult retData()
{
using (var context = new DBModel())
{
var users = context.Database.SqlQuery<portal_testcase_scn>("SELECT *,Portal_Version.build FROM [portal_testcase_scn] inner join Portal_Version on [portal_testcase_scn].row_num=Portal_Version.row_num").ToList();
return Ok(users);
}
}









share|improve this question
















I need to pass SQL Query(with Joins) as parameter to my API and retrun the results. But the result is dependent on the using the below code. I there any way to get this fixed. Please advise.



Expected results should be all the columns from the query into var users variable.



public IHttpActionResult retData()
{
using (var context = new DBModel())
{
var users = context.Database.SqlQuery<portal_testcase_scn>("SELECT *,Portal_Version.build FROM [portal_testcase_scn] inner join Portal_Version on [portal_testcase_scn].row_num=Portal_Version.row_num").ToList();
return Ok(users);
}
}






c# asp.net-web-api frameworks entity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 3:22









Backs

19.2k33159




19.2k33159










asked Jan 3 at 3:19









Shreyas MuraliShreyas Murali

14




14













  • Hi, what problem do you have?

    – Backs
    Jan 3 at 3:23











  • I am retrieving data from portal_testcase_scn and Portal_Version table using joins. But API is returning data from portal_testcase_scn. Because I have mentioned portal_testcase_scn as datatype within SqlQuery<>. Is there a way to get all teh columsn from both the tables in API?

    – Shreyas Murali
    Jan 3 at 3:48



















  • Hi, what problem do you have?

    – Backs
    Jan 3 at 3:23











  • I am retrieving data from portal_testcase_scn and Portal_Version table using joins. But API is returning data from portal_testcase_scn. Because I have mentioned portal_testcase_scn as datatype within SqlQuery<>. Is there a way to get all teh columsn from both the tables in API?

    – Shreyas Murali
    Jan 3 at 3:48

















Hi, what problem do you have?

– Backs
Jan 3 at 3:23





Hi, what problem do you have?

– Backs
Jan 3 at 3:23













I am retrieving data from portal_testcase_scn and Portal_Version table using joins. But API is returning data from portal_testcase_scn. Because I have mentioned portal_testcase_scn as datatype within SqlQuery<>. Is there a way to get all teh columsn from both the tables in API?

– Shreyas Murali
Jan 3 at 3:48





I am retrieving data from portal_testcase_scn and Portal_Version table using joins. But API is returning data from portal_testcase_scn. Because I have mentioned portal_testcase_scn as datatype within SqlQuery<>. Is there a way to get all teh columsn from both the tables in API?

– Shreyas Murali
Jan 3 at 3:48












1 Answer
1






active

oldest

votes


















0














You can use Linq.



using (var context = new DBModel())
{
List<object> users = (from c in context.portal_testcase_scn
join d in context.Portal_Version
on c.row_num equals d.row_num
select new {
build=d.build,
}).ToList();
return Ok(users);
}





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%2f54015901%2fhow-to-use-sql-joins-in-web-api%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














    You can use Linq.



    using (var context = new DBModel())
    {
    List<object> users = (from c in context.portal_testcase_scn
    join d in context.Portal_Version
    on c.row_num equals d.row_num
    select new {
    build=d.build,
    }).ToList();
    return Ok(users);
    }





    share|improve this answer




























      0














      You can use Linq.



      using (var context = new DBModel())
      {
      List<object> users = (from c in context.portal_testcase_scn
      join d in context.Portal_Version
      on c.row_num equals d.row_num
      select new {
      build=d.build,
      }).ToList();
      return Ok(users);
      }





      share|improve this answer


























        0












        0








        0







        You can use Linq.



        using (var context = new DBModel())
        {
        List<object> users = (from c in context.portal_testcase_scn
        join d in context.Portal_Version
        on c.row_num equals d.row_num
        select new {
        build=d.build,
        }).ToList();
        return Ok(users);
        }





        share|improve this answer













        You can use Linq.



        using (var context = new DBModel())
        {
        List<object> users = (from c in context.portal_testcase_scn
        join d in context.Portal_Version
        on c.row_num equals d.row_num
        select new {
        build=d.build,
        }).ToList();
        return Ok(users);
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 3 at 4:53









        StoneStone

        711




        711
































            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%2f54015901%2fhow-to-use-sql-joins-in-web-api%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

            MongoDB - Not Authorized To Execute Command

            How to fix TextFormField cause rebuild widget in Flutter

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith