Hi folks,
imagine there are two tables.
Order
+----------------+
| ID |
| Name |
+----------------+
OrderStatus
+----------------+
| ID |
| OrderId |
| StatusId |
+----------------+
A Order can have more than one OrderStatus, which could be called OrderStatusHistory. I'll have an StronglyTypeObject Order, which is descripted as follows
namespace my.project
{
public class Order
{
Int64 OrderId { get; set; }
String Name { get; set; }
Int64 StatusId { get; set; }
}
}
This StatusId in the Order Object is meant to be the current (last) StatusId from the OrderStatus Table.
I have tried to build a IQueryable List of Objects with LINQ. Here is my, not working ;), Linq Code
var result = from r in dbContext.ORDER
select new Order
{
OrderId = r.ID,
Name = r.Name,
StatusId = dbContext.OrderStatus
.Where(p => p.OrderId == r.ID).Last().StatusId
}
I have also tried working with Max(p=>p.XXX) but it hasn't worked out. Does anyone has a hint on this problem?
Any Help would be much appreciated...
Gordon