Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, January 10, 2012 6:32 AM
Please help me with this.
var cartItems = from product in tsContainer.TS_Products where product.ProductId == TSObjects.GetProductIds();
where GetProductIds() method is below
private const string PRODUCTID_ARRAY = "ProductID_Array";
public static void AddProductId(int productId)
{
if (HttpContext.Current.Session[PRODUCTID_ARRAY] == null)
HttpContext.Current.Session[PRODUCTID_ARRAY] = new List<int>();
List<int> pArray = (List<int>)HttpContext.Current.Session[PRODUCTID_ARRAY];
pArray.Add(productId);
}
public static List<int> GetProductIds()
{
if (HttpContext.Current.Session[PRODUCTID_ARRAY] != null)
return (List<int>)HttpContext.Current.Session[PRODUCTID_ARRAY];
return null;
}
I'm getting error here "where product.ProductId == TSObjects.GetProductIds();"
Error-
Operator '==' cannot be applied to operands of type 'int' and 'System.Collections.Generic.List<int>'
All replies (7)
Tuesday, January 10, 2012 7:07 AM ✅Answered
Try this code,
var cartItems = from product in tsContainer.TS_Products where TSObjects.GetProductIds().Contains(product.ProductId) select product;
I hope this helps.
Please mark this post as answer if it solved your problem. Happy Programming!
Tuesday, January 10, 2012 7:15 AM ✅Answered
Priya,
Take another look at my code. You are missing 'select' at the end of query.
Please mark this post as answer if it solved your problem. Happy Programming!
Tuesday, January 10, 2012 6:42 AM
You are comparing a member of type int with a object list. it is not allowed.try the below
tsContainer.TS_Products.where(product => TSObjects.GetProductIds().Contains(product.ProductId))
Surender Singh Bhadauria
Tuesday, January 10, 2012 6:50 AM
Thank you.....
var cartItems = from product in tsContainer.TS_Products where(product => TSObjects.GetProductIds().Contains(product.ProductId));
I'm getting error
Cannot convert lambda expression to type 'bool' because it is not a delegate type
A local variable named 'product' cannot be declared in this scope because it would give a different meaning to 'product', which is already used in a 'parent or current' scope to denote something else
Tuesday, January 10, 2012 7:09 AM
When I used this
var cartItems = from product in tsContainer.TS_Products where TSObjects.GetProductIds().Contains(product.ProductId);
Error 1 A query body must end with a select clause or a group clause
Error 2 The type of the expression in the select clause is incorrect. Type inference failed in the call to 'Select'.
Tuesday, January 10, 2012 7:16 AM
var cartItems = from product in tsContainer.TS_Products where TSObjects.GetProductIds().Contains(product.ProductId) select product;
Is this correct?
Tuesday, January 10, 2012 7:17 AM
Thank you guys....