Entity Framework Join two tables together for displaying in MVC view
up vote
0
down vote
favorite
I am new to Entity Framework and LINQ and I am having some difficulty in linking two tables together for a view so that it can be displayed to the end user. I have a list of prices which are displayed in Euro in one table and in the other table I have an exchange rate table. Currently this is only displayed in Euro and I would like to display this in GBP.
Previously I was able to return the single view table from my controller using the following:
return View(db.Prices.ToList());
Now that I am attempting to return the two tables I am not sure what I need to do but I have tried the following code to join the tables:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE
The Prices class does not have a column for GBP price so I need to multiply the euro price by the exchange rate for the trading day and display this in my view but the backing model of the view is set to Prices, would I be better to come up with a view model for this or could it be done simpler?
c# entity-framework model-view-controller
add a comment |
up vote
0
down vote
favorite
I am new to Entity Framework and LINQ and I am having some difficulty in linking two tables together for a view so that it can be displayed to the end user. I have a list of prices which are displayed in Euro in one table and in the other table I have an exchange rate table. Currently this is only displayed in Euro and I would like to display this in GBP.
Previously I was able to return the single view table from my controller using the following:
return View(db.Prices.ToList());
Now that I am attempting to return the two tables I am not sure what I need to do but I have tried the following code to join the tables:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE
The Prices class does not have a column for GBP price so I need to multiply the euro price by the exchange rate for the trading day and display this in my view but the backing model of the view is set to Prices, would I be better to come up with a view model for this or could it be done simpler?
c# entity-framework model-view-controller
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am new to Entity Framework and LINQ and I am having some difficulty in linking two tables together for a view so that it can be displayed to the end user. I have a list of prices which are displayed in Euro in one table and in the other table I have an exchange rate table. Currently this is only displayed in Euro and I would like to display this in GBP.
Previously I was able to return the single view table from my controller using the following:
return View(db.Prices.ToList());
Now that I am attempting to return the two tables I am not sure what I need to do but I have tried the following code to join the tables:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE
The Prices class does not have a column for GBP price so I need to multiply the euro price by the exchange rate for the trading day and display this in my view but the backing model of the view is set to Prices, would I be better to come up with a view model for this or could it be done simpler?
c# entity-framework model-view-controller
I am new to Entity Framework and LINQ and I am having some difficulty in linking two tables together for a view so that it can be displayed to the end user. I have a list of prices which are displayed in Euro in one table and in the other table I have an exchange rate table. Currently this is only displayed in Euro and I would like to display this in GBP.
Previously I was able to return the single view table from my controller using the following:
return View(db.Prices.ToList());
Now that I am attempting to return the two tables I am not sure what I need to do but I have tried the following code to join the tables:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE
The Prices class does not have a column for GBP price so I need to multiply the euro price by the exchange rate for the trading day and display this in my view but the backing model of the view is set to Prices, would I be better to come up with a view model for this or could it be done simpler?
c# entity-framework model-view-controller
c# entity-framework model-view-controller
asked Nov 8 at 10:41
Seán-Pól
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You need something like:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE)
.Select(x => new {
PriceInEuro = x.a.PriceInEuro,
PriceInSterling = x.a.PriveInEuro * x.b.ExchangeRate})
.ToList();
Warning - not tested.
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You need something like:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE)
.Select(x => new {
PriceInEuro = x.a.PriceInEuro,
PriceInSterling = x.a.PriveInEuro * x.b.ExchangeRate})
.ToList();
Warning - not tested.
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
add a comment |
up vote
0
down vote
accepted
You need something like:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE)
.Select(x => new {
PriceInEuro = x.a.PriceInEuro,
PriceInSterling = x.a.PriveInEuro * x.b.ExchangeRate})
.ToList();
Warning - not tested.
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You need something like:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE)
.Select(x => new {
PriceInEuro = x.a.PriceInEuro,
PriceInSterling = x.a.PriveInEuro * x.b.ExchangeRate})
.ToList();
Warning - not tested.
You need something like:
var result = (from a in db.Prices
join b in db.ExchangeRatse on a.TRADE_DATE equals b.TRADE_DATE)
.Select(x => new {
PriceInEuro = x.a.PriceInEuro,
PriceInSterling = x.a.PriveInEuro * x.b.ExchangeRate})
.ToList();
Warning - not tested.
answered Nov 8 at 11:00
Peter Smith
3,43453963
3,43453963
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
add a comment |
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
cheers just created a view model and did something similar to this
– Seán-Pól
Nov 8 at 12:16
add a comment |
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
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206033%2fentity-framework-join-two-tables-together-for-displaying-in-mvc-view%23new-answer', 'question_page');
}
);
Post as a guest
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
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
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