I have two tables.
Orders
OrderID | UserID | OrderTotal
1 | 1 | 100
2 | 2 | 110
3 | 1 | 120
Users
UserId | ProprtyType | PropertyValue
1 | 1 | Kevin
1 | 2 | Nolan
1 | 1 | FirstName
1 | 2 | Surname
Using the following Query
var query = from orders in context.Orders
join users in context.Users on orders.UserID equals user.UserID
where userData.Type == 211 || userData.Type == 212
1 | 1 | 100 | Kevin
1 | 1 | 100 | Nolan
2 | 2 | 110 | FirstName
2 | 2 | 110 | Surname
3 | 1 | 120 | Kevin
3 | 1 | 120 | Nolan
Is it possible in Entity frame work to combine the results so it returns the following
1 | 1 | 100 | Kevin | Nolan
2 | 2 | 110 | FirstName | Surname
3 | 1 | 120 | Kevin | Nolan
Or
1 | 1 | 100 | Kevin Nolan
2 | 2 | 110 | FirstName Surname
3 | 1 | 120 | Kevin Nolan
Thanks
That Users table is really badly designed, IMO. If you keep the table layout, please rename it UserProperties. Also, your example code doesn’t match your table layout or the suggested results.
That being said, you can do something like this:
One good thing about Entity Framework is that the actual SQL queries are deferred as long as possible. So just querying for firstnames and lastnames will not generate a database connection. That comes later. Unfortunately, your table design makes it really difficult to utilize those benefits of EF.