how to convert lambda expression with statement body to an expression tree
I have problem with my code, I don't know problem because am new to c#, But am trying to convert a project from Asp.Net MVC to Core. can someone help me with this code.
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
//error is from this .Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
asp.net-mvc asp.net-core
add a comment |
I have problem with my code, I don't know problem because am new to c#, But am trying to convert a project from Asp.Net MVC to Core. can someone help me with this code.
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
//error is from this .Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
asp.net-mvc asp.net-core
Share us your current model defination. For Asp.Net, you could define many-to-many relationship directly. But for asp.net core, you need to define middle class to implement many-to-many relationship. You need to redesign your model.
– Tao Zhou
Dec 31 '18 at 2:32
add a comment |
I have problem with my code, I don't know problem because am new to c#, But am trying to convert a project from Asp.Net MVC to Core. can someone help me with this code.
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
//error is from this .Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
asp.net-mvc asp.net-core
I have problem with my code, I don't know problem because am new to c#, But am trying to convert a project from Asp.Net MVC to Core. can someone help me with this code.
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
//error is from this .Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
asp.net-mvc asp.net-core
asp.net-mvc asp.net-core
edited Dec 28 '18 at 11:24
Neel Darji
63111
63111
asked Dec 28 '18 at 10:51
Ayomide MatanmiAyomide Matanmi
11
11
Share us your current model defination. For Asp.Net, you could define many-to-many relationship directly. But for asp.net core, you need to define middle class to implement many-to-many relationship. You need to redesign your model.
– Tao Zhou
Dec 31 '18 at 2:32
add a comment |
Share us your current model defination. For Asp.Net, you could define many-to-many relationship directly. But for asp.net core, you need to define middle class to implement many-to-many relationship. You need to redesign your model.
– Tao Zhou
Dec 31 '18 at 2:32
Share us your current model defination. For Asp.Net, you could define many-to-many relationship directly. But for asp.net core, you need to define middle class to implement many-to-many relationship. You need to redesign your model.
– Tao Zhou
Dec 31 '18 at 2:32
Share us your current model defination. For Asp.Net, you could define many-to-many relationship directly. But for asp.net core, you need to define middle class to implement many-to-many relationship. You need to redesign your model.
– Tao Zhou
Dec 31 '18 at 2:32
add a comment |
2 Answers
2
active
oldest
votes
if Context.Payments.Bills is defined
then you can use the code below
context.Payments.FromSql(
"select * from dbo.Payments p where p.OrderStatus = 'Approved' order by p.Service").Include(x => x.Bills);
needs to return Bills as well inside Payments p.Bills
Reference: https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#including-related-data
add a comment |
For lambda expression with statement body to an expression tree
this issue, you could not pass x.p.Bill = x.b;
to linq query statement, try something like below:
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
.ToList()
.Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
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%2f53957349%2fhow-to-convert-lambda-expression-with-statement-body-to-an-expression-tree%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
if Context.Payments.Bills is defined
then you can use the code below
context.Payments.FromSql(
"select * from dbo.Payments p where p.OrderStatus = 'Approved' order by p.Service").Include(x => x.Bills);
needs to return Bills as well inside Payments p.Bills
Reference: https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#including-related-data
add a comment |
if Context.Payments.Bills is defined
then you can use the code below
context.Payments.FromSql(
"select * from dbo.Payments p where p.OrderStatus = 'Approved' order by p.Service").Include(x => x.Bills);
needs to return Bills as well inside Payments p.Bills
Reference: https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#including-related-data
add a comment |
if Context.Payments.Bills is defined
then you can use the code below
context.Payments.FromSql(
"select * from dbo.Payments p where p.OrderStatus = 'Approved' order by p.Service").Include(x => x.Bills);
needs to return Bills as well inside Payments p.Bills
Reference: https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#including-related-data
if Context.Payments.Bills is defined
then you can use the code below
context.Payments.FromSql(
"select * from dbo.Payments p where p.OrderStatus = 'Approved' order by p.Service").Include(x => x.Bills);
needs to return Bills as well inside Payments p.Bills
Reference: https://docs.microsoft.com/en-us/ef/core/querying/raw-sql#including-related-data
answered Dec 28 '18 at 11:39
SimonareSimonare
11.3k11737
11.3k11737
add a comment |
add a comment |
For lambda expression with statement body to an expression tree
this issue, you could not pass x.p.Bill = x.b;
to linq query statement, try something like below:
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
.ToList()
.Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
add a comment |
For lambda expression with statement body to an expression tree
this issue, you could not pass x.p.Bill = x.b;
to linq query statement, try something like below:
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
.ToList()
.Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
add a comment |
For lambda expression with statement body to an expression tree
this issue, you could not pass x.p.Bill = x.b;
to linq query statement, try something like below:
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
.ToList()
.Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
For lambda expression with statement body to an expression tree
this issue, you could not pass x.p.Bill = x.b;
to linq query statement, try something like below:
using (var context = new UniversityDbContext())
{
var payments =
(from p in context.Payments
.FromSql(
"select * from dbo.Payments p inner join dbo.Bills b on p.BillId = b.Id where p.OrderStatus = 'Approved' order by p.Service")
join b in context.Bills on p.BillId equals b.Id
where b.User == userId
select new { p, b })
.ToList()
.Select(x =>
{
x.p.Bill = x.b;
return x.p;
}).ToList(); // To this
var t = payments.Count();
return payments;
}
answered Dec 31 '18 at 3:09
Tao ZhouTao Zhou
5,91131230
5,91131230
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%2f53957349%2fhow-to-convert-lambda-expression-with-statement-body-to-an-expression-tree%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
Share us your current model defination. For Asp.Net, you could define many-to-many relationship directly. But for asp.net core, you need to define middle class to implement many-to-many relationship. You need to redesign your model.
– Tao Zhou
Dec 31 '18 at 2:32