Question

Does anyone have the faintest idea what this error means please and how to resolve it? All my research is drawing a blank, I can see how to set it on MSDN but it doesn't explain it in a way that explains to me what the issue is. If I remove some of my LINQ queries to set viewbag items then it seems to resolve it but the moment I set new ones and pass them into my view to generate a mail for MVCMailer it comes back. Not sure if its a viewbag issue or simply that I am calling too many linq queries to generate them to pass to the view.

I am very stuck (again)..........

Cheers, Steve.

DbLimitExpression requires a collection argument. Parameter name: argument Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: DbLimitExpression requires a collection argument. Parameter name: argument

An example of the code is:

            var VBSalutation = from A in context.Salutations
                where A.SalutationId == policytransaction.SalutationId
                select A.SalutationName;
        ViewBag.Salutation = VBSalutation.FirstOrDefault();

This is repeated for various parameters and then passed to the view.

Was it helpful?

Solution

Well, I faced a similar problem and solved it. Problem was in WHERE clause: data type of left side equal operator (=) sign was not matching with data type of right side. So in your scenario:

where A.SalutationId == policytransaction.SalutationId

SalutationID of A might be an INT and SalutationId of policytransaction might be a string (This is how it was in my case).

I solved it by assigning policytransaction.SalutationId to an Int variable and using it:

int myIntVariable = Convert.ToInt16(policytransaction.SalutationId);
...//some code here
where A.SalutationId == myIntVariable;

Please also note that you cannot directly cast your variables directly in Linq else you'll get an error "LINQ to Entities does not recognize the method". You'll have to use a temp variable and then apply the where clause.

OTHER TIPS

Try ViewBag.Salutation = VBSalutation.SingleOrDefault();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top