We use an EDMX to access our database with Entity Framework. Before you comment: we have our reasons not to use code-first. Today we encountered a small problem with linq to entities and validating a varchar field that contains an integer value. Again: we have our reasons. Think about key-value pairs.
An excellent answer of Joel Mueller on stackoverflow.com helped us overcome this problem. In short we had to add a function to our edmx conceptual model. The link above has all te details.
<Function Name="ParseInt" ReturnType="Edm.Int32"> <Parameter Name="stringvalue" Type="Edm.String"/> <DefiningExpression> CAST(stringvalue as Edm.Int32) </DefiningExpression> </Function>
The validation works like a charm now. This is what EF generates (see the CAST?):
SELECT [GroupBy1].[A1] AS [C1] FROM ( SELECT COUNT(1) AS [A1] FROM [dbo].[Table] AS [Extent1] WHERE ([Extent1].[Key] = @p__linq__0) AND (( CAST( [Extent1].[Value] AS int) < @p__linq__1) OR ( CAST( [Extent1].[Value] AS int) > @p__linq__2)) ) AS [GroupBy1]