0

how to write the linq query with these conditions..first we have to check the OrderType if this is true then and condition should be checked.How to write the query..if i close the condition at .OrderType.XYZ) then it says 'zj' doesn't belong to the current context..if we remove that no error but we r not getting the req result

bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem }).
   .Where((zj => wo.OrderId== (int)BL.OrderType.PQR || zj.OrderId== (int)BL.OrderType.XYZ)
           &&( zj.OrderId== (int)BL.Statuses.Assigned
             || zj.OrderId== (int)BL.Statuses.Planned 
             || zj.OrderId== (int)BL.Statuses.InProgess
             || zj.OrderId== (int)BL.Statuses.Paused 
             || zj.OrderId== (int)BL.Statuses.Ready)).Any();
return btnEnable; 
1
  • You ask "first we have to check the OrderType if this is true then and condition should be checked." but you're clearly using enums in your example. Commented Feb 29, 2012 at 22:07

3 Answers 3

2

I think this is due to some misplaced brackets. You have .Where((zj => ...) ... zj ...). The variable zj doesn't exist outside of the first set of brackets. It should be something like:

bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem })
   .Where(zj => (wo.OrderId== (int)BL.OrderType.PQR || zj.OrderId== (int)BL.OrderType.XYZ)
           && (zj.OrderId== (int)BL.Statuses.Assigned
             || zj.OrderId== (int)BL.Statuses.Planned 
             || zj.OrderId== (int)BL.Statuses.InProgess
             || zj.OrderId== (int)BL.Statuses.Paused 
             || zj.OrderId== (int)BL.Statuses.Ready)).Any();
return btnEnable; 
Sign up to request clarification or add additional context in comments.

Comments

2

You appear to have a mismatched parenthesis problem.

.Where((zj => wo.OrderId== (int)BL.OrderType.PQR || zj.OrderId== (int)BL.OrderType.XYZ) 
       ^                                                                              ^

That's mucking with the scope of your variable. Revisit it.

Comments

2
var readyStats = new [] {
   (int)BL.Statuses.Assigned,
   (int)BL.Statuses.Planned,
   (int)BL.Statuses.InProgess,
   (int)BL.Statuses.Paused,
   (int)BL.Statuses.Ready,
};

var orderTypes = new [] {
    (int)BL.OrderType.PQR,
    (int)BL.OrderType.XYZ
}

bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem }).
   .Where(wo => orderTypes.Contains(wo.OrderId) && readyStats.Contains(wo.OrderId)).Any();

or

bool btnvisible= datacontext.GetOrders(new List<Items> { selectedItem }).
       .Any(wo => orderTypes.Contains(wo.OrderId) && readyStats.Contains(wo.OrderId));

I think the problem is here:

.Where((zj => wo.

The right version should be:

   .Where(zj => zj.

Comments

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.