I created two entities and they have navigation properties.
var list = from u in storeDB.Users
join a in storeDB.Accounts
on u.Id equals a.Id
select new { u, a };
if I do a
foreach( user in list){
<span>user.Name, user.Money</span>
}
It does not work. My question is how can I display the content from the result attributes of both tables, that is, of the join??
Users: has Name, Id
Accounts: has Id, Money
The properties on the anonymous object are
u
anda
as you've named them. You probably want to give them better names or, better yet, simply select the properties you are interested in. I would give them explicit names, but you could omit that if the names you want are the same as the property names and there aren't any conflicts.Then use them as
Try including the related objects.
e.g.
I suspect you are using this in an MVC view so you need to create a view model for your combined user and account objects and send an Enumerable of it at the model.
Then in your query do this:
Pass the list as your model. Your view should be strongly typed;
IEnumerable<UserAccountVM>
should work. Then do this in your view: