I'm storing enum values in the database (postgres) as string types. When I
project the DbLinq classes into my business classes I parse the string values
back into its original enum value. It looks like this:
// DbLinq class:
public class DbLinq
{
long ID { get; set; }
string MyEnumVal { get; set; }
}
// Biz classes:
public enum MyEnumValue { One, Two }
public class MyClass
{
long Id { get; set; }
MyEnumValue MyEnumVal { get; set; }
}
// Projection code:
public IQueryable<MyClass> GetAll()
{
using (var context = GetDbLinqContext())
{
return
from r in context.Table
select new MyClass
{
Id = r.ID,
MyEnumVal = (MyEnumValue)Enum.Parse(typeof(MyEnumValue), r.MyEnumVal),
}
}
}
Now this works just fine if I simply loop over the items returned from
GetAll(), but things blow up if I want to filter the items. I.e.
GetAll().Where(i => i.MyEnumVal == MyEnumValue.One)
I realize when this is included in the where clause it must send the parsing
logic to the postgres server and could be very complicated, but I figured I go
ahead and check.
Any ideas?
Original issue reported on code.google.com by abe.gill...@gmail.com on 29 Nov 2010 at 4:27
Original issue reported on code.google.com by
abe.gill...@gmail.com
on 29 Nov 2010 at 4:27