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;
}
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
add a comment |
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
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
add a comment |
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
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
c# asp.net-web-api frameworks entity
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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);
}
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%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
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);
}
add a comment |
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);
}
add a comment |
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);
}
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);
}
answered Jan 3 at 4:53
StoneStone
711
711
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%2f54015901%2fhow-to-use-sql-joins-in-web-api%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
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