0

I having a trouble with a query

I need to take out the SHIPMENT from GetAllOrderData - the same place where you can find POD_DATE and RECEIVE_NAME...but I get an error

Error 1 The name 'x' does not exist in the current context

My code is:

public IEnumerable<ReportItemDTO> GetTaskProgress(DateTime targetDate)
{
   try
   {
      var startDate = targetDate.Date;
      var endDate = startDate.AddDays(1);
      OrderDataRepository rep = new OrderDataRepository();

      var query = rep.GetAllOrderData()
                  .Where(x => x.POD_DATE >= startDate && x.POD_DATE <= endDate)
                  .GroupBy(o => o.User)
                  .Select(g => new ReportItemDTO
                    {
                      DriverId = g.Key.Id,
                      PdriverName = g.Key.Name,
                      OrderCount = g.Count(),
                      ReportedOrdersCount = g.Count(o => o.RECEIVE_NAME != null),
                      SHIPMENT = (x.SHIPMENT)
                    } );

      return query;
0

1 Answer 1

1
  SHIPMENT = (x.SHIPMENT)

Well you are within a grouping when you try to make that assignment - there are many shipments in each grouping not just one - in fact all shipments for that particular user. Assuming you want a collection of them you could do:

Shipments = g.Select( x=> x.SHIPMENT)

Edit:

If you just want the first shipment for each user (somewhat illogical but fits your data model):

SHIPMENT = g.Select( x=> x.SHIPMENT).First()
Sign up to request clarification or add additional context in comments.

11 Comments

Error 1 Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<string>' to 'string'
@user1021182: Your Shipments property in ReportItemDTO has to be of type IEnumerable<string>
its a string public string SHIPMENT { get; set; }
Did you read the answer? There are many shipments within that group - how do you want to get a single shipment out of it?
yes , but those are the same shipments...i mean each of the users has the same shipment code...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.