Reputation: 18916
I have an Entity
in my model which has an Enumeration
type property.
I'm binding a Gridview
with an EntityDataSource
to it. By now, everything is fine.
But how can I specify a WHERE
clause on a MyEntity.MyEnumProperty
?
Here is what I have tried so far:
Convert.ToInt32(it.MyEnumProperty) = @MyParam // Does not work
CONVERT(it.MyEnumProperty AS INT) = @MyParam // Still does not work
I also tried to set Int32
to DbType
of my params
for both these values but it fails. Also, I tried to bind it to a control or specifying a default value but it always fails saying it's impossible to convert a String
value to MyEnum
.
I know it may be pretty simple but all my research on Google returned no answer about this.
Upvotes: 2
Views: 778
Reputation: 18916
Pretty simple finaly.
Easiest way were to specify manualy my where clause and convert it. I'd found this answer somewhere saying it's impossible. It wasn't, but only in previous version but work perfectly with EF4.
Here is my where clause :
<asp:EntityDataSource [...]
Where="CAST(it.MyEnumProperty AS System.Int32) = @MyParamInWhereClauseWith">
<WhereParameters>
<asp:Parameter Name="MyEnumProperty" DbType="Int32" DefaultValue="1" />
</WhereParameters>
</asp:EntityDataSource>
Upvotes: 3