You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
I made a FK by dragging CatId from Category table to CatId to the Reviews table.
The First DDL works fine but when I when I try to apply the filter I get that same error message. I would add that the where filter does not give me the chance to chose "=" , it only gives me the option for "==" whether I have an int or a string (?). The book shows "=".
Here's the error message: Operator '==' incompatible with operand types 'Int32' and 'Object'
== is the equality operator in C#; = is used in VB. Maybe the book shows the VB version? Can't recall exactly and I don't know what image you're referring to...
And where exactly do you see this "=="? In which dialog?
I found the problem. I honestly don't understand it but the fix did work. Here's a link to it and the post I found it on is below. I ended up adding default="0" to Where parameters of the second linqdatasource that uses the DropdownList
When working with the LinqDataSource, you may get the exceptions listed below.
1. Operator '==' incompatible with operand types 'Int32' and 'Object'
The exception occurs because anytime a ControlParameter in the WhereParameters collection (IDictionary<string, object>) is null, it gets treated as type Object causing the LINQ dynamic expression parser comparison to fail. Consider the code snippet below:
This is part of the classic Master/Details scenario where the LinqDataSource fetches the Order Details based on the OrderID selected in the GridView1.
When the page loads the first time, the OrderID ControlParameter is equal to GridView1.SelectedValue. GridView1.SelectedValue is null since no record has been selected in the GridView1 yet. Unfortunately, the LinqDataSource still attempts to fetch the data. The Linq expression parser treats the null parameter as type Object and the comparison fails because it was expecting type Int32.
What we need here is a way to prevent the Select from occurring when any parameter is null. The LinqDataSource, unlike the SqlDataSource, for some reason, does not have a CancelSelectOnNullParameter property. This property when set to true, will cancel the select when any parameter in the SelectParameters collection is null.
We can implement this by handling the Selecting event of the LinqDataSource and call the Cancel method when any WhereParameter is null like so:
Unfortunately not long after that the program starting not loading the datacontext giving me a "Cannot load Type TreatReviewsDataContext" even though I hadn't touched the data context. Another page gave me the same error. I created a new datacontext to no avail; it simply will not load it. (?)
I found the problem. I honestly don't understand it but the fix did work.
It makes sense if you consider the fact the drop down list or other control you're using has no value when the page loads the first time. In other words, you try to filter on something that has no value. By setting the default value to 0, you now filter on that value (and pobably get no records back).
But I guess the error message is misleading. Cannot convert null to Int32 would have been more appropriate... ;-)
Unfortunately not long after that the program starting not loading the datacontext giving me a "Cannot load Type TreatReviewsDataContext" even though I hadn't touched the data context.
Impossible for me to say something about this other than saying it's impossible for me to say something about it. Clearly something has changed but I can't see what or what you need to do to fix it. Google for the exact error message (but leave out your own type name) and see if that brings up something useful...
Finally fixed it. I googled linqdatasource and 'cannot load type' and came up with a namespace problem. I went to the Object Browser, found out the namespace (C!), attached it to it and it loaded right up. I don't know why this happened but I'm glad its working now. Original error message is below by the way.
Server Error in '/PR1' Application.Could not load type 'TreatReviewsDataContext'.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.Web.HttpException: Could not load type 'TreatReviewsDataContext'.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[HttpException (0x80004005): Could not load type 'TreatReviewsDataContext'.]
System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +8829125
[InvalidOperationException: Could not find the type specified in the ContextTypeName property of LinqDataSource 'LinqDataSource1'.]
System.Web.UI.WebControls.LinqDataSourceView.CreateContextAndTable(DataSourceOperation operation) +680
System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +383
System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +19
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +842
Last edited by Cort; March 16th, 2010 at 08:21 PM.