I found a simple problem today. Here is the deal, there were several times where I had to base a LinqDataSource off a Guid that I would set in the Page_Load(). I created an<asp:HiddenField /> to hold the value so all my DataSources could pull it from the control. The HiddenField control’s value is stored as a string, so I would have to convert the guid to a string. After doing this, I was getting the following error:
Operator ‘==’ incompatible with operand types ‘Guid’ and ‘String’
After looking around in my code and some forums, I found the answer: Linq is strongly cast and Visual Studio 2008 most like set the “where” clause to something like this:
<asp:LinqDataSource ID=”ldsProducs” runat=”server”
ContextTypeName=”CartDataContext” EnableDelete=”True” EnableInsert=”True”
EnableUpdate=”True” OrderBy=”Product_UPC1″ TableName=”Product_UPCs”
Where=”Product_IID == @Product_IID”>
<WhereParameters>
<asp:ControlParameter ControlID=”hfProductIID” Name=”Product_IID”
PropertyName=”Value” Type=”Object” />
</WhereParameters>
</asp:LinqDataSource>
However, because Linq is strongly cast you can’t perform an == operand on a String and Guid, so I changed the following:
<asp:LinqDataSource ID=”ldsProducs” runat=”server”
ContextTypeName=”CartDataContext” EnableDelete=”True” EnableInsert=”True”
EnableUpdate=”True” OrderBy=”Product_UPC1″ TableName=”Product_UPCs”
Where=”Product_IID == Guid(@Product_IID)”>
<WhereParameters>
<asp:ControlParameter ControlID=”hfProductIID” Name=”Product_IID”
PropertyName=”Value” Type=”Object” />
</WhereParameters>
</asp:LinqDataSource>
Now it’ll convert the HiddenField’s value to a Guid and compair.