views:

109

answers:

2

Two tables (MainTable and EventType). EventType is represented in code as an enumeration and is foreign keyed in the database so that it looks like;

Public enum EventTypeId As Integer
    Blah = 1
    Blurgh = 2
    Whoo = 3
End Enum

I can run the following query fine;

From M in dbx.MainTable Where M.EventType.EventTypeId = 1

But I can't do this (psuedo code);

From M in dbx.MainTable Where M.EventType.EventTypeId.Contains(EventTypeId.Blah,EventTypeId.Whoo)

The 2nd approach is more readable and maintainable as it links to the enum, but I can't find a construct in EF that allows me to do this.

This is the current version of EF, not .Net 4.0.

In summary, what I want to do in SQL is easy, it just needs to be in EF;

Select * From MainTable Where EventTypeId In (1,3);
+2  A: 

I found a similar question about the IN-statement in LINQ.

p2u
I did it as per one of the comments in your link, by using ToList and then running the Where on that, which is messy but it avoids changing the DB. Did I mention I have a growing dislike of EF?
Ryan ONeill
A: 

Never tried something similar, but have you tested if it works by casting your enumerations to integers, as the following?

(int)EventTypeID.Blah

Sorry, can't help much more than this without trying for myself, what is not possible right now.

wintermute
Nope, it hates that too as it tries to do it db side and complains that it does not know about the type.
Ryan ONeill