निम्नलिखित कोड:LINQ से SQL - आप ORDER BY के बाद WHERE का उपयोग क्यों नहीं कर सकते?
// select all orders
var orders = from o in FoodOrders
where o.STATUS = 1
order by o.ORDER_DATE descending
select o;
// if customer id is specified, only select orders from specific customer
if (customerID!=null)
{
orders = orders.Where(o => customerID.Equals(o.CUSTOMER_ID));
}
मुझे निम्न त्रुटि देता है:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'System.Linq.IOrderedQueryable'. An explicit conversion exists (are you missing a cast?)
मैं अंत में छँटाई करके त्रुटि को ठीक:
// select all orders
var orders = from o in FoodOrders
where o.STATUS = 1
select o;
// if customer id is specified, only select orders from specific customer
if (customerID!=null)
{
orders = orders.Where(o => customerID.Equals(o.CUSTOMER_ID));
}
// I'm forced to do the ordering here
orders = orders.OrderBy(o => o.ORDER_DATE).Reverse();
लेकिन मैं सोच रहा हूँ यह सीमा जगह क्यों है? एपीआई को इस तरह से डिज़ाइन किया गया था कि order by
ऑपरेटर का उपयोग करने के बाद आप where
बाधा नहीं जोड़ सकते हैं?
नो-सेशन जिज्ञासा क्या है? – MCS
यह वास्तव में एक संपूर्ण जवाब है और एक महान स्पष्टीकरण है। धन्यवाद। – MCS
@ एमएमसीएस: मेरा मतलब है नो-ऑप प्रक्षेपण - एक चुनिंदा खंड जो कि पहले से मौजूद है का चयन करता है, अगर आप देखते हैं कि मेरा क्या मतलब है। –