Using ADO.net Entity Framework 4 with Enumerations? How do I do it? -
question 1: playing around ef4 , have model class :
public class candidate { public int id {get;set;} public string fullname {get;set;} public gender sex {get;set;} public educationlevel highestdegreetype {get;set;} }
here gender , educationlevel enums like:
public enum gender {male,female,undisclosed} public enum educationlevel {highschool,bachelors,masters,doctorate}
how candidate class , gender , educationlevel working ef4 if:
- i model first development
- i db first development
edit: moved question related object context question here.
apparently int <-> enum
won't supported in initial release of ef4. agree sucks.
i using property casting me
public partial class myentity { public myenum hurrenum {get{return (myenum)hurr;} set{hurr = (int)value;}} }
it doesn't bad if name stuff "correctly" (which means, doesn't stupid). instance, have reasoncode enum that's stored reason in database, have reason , reasoncode versions of property. works out enough, now.
first, i'm starting use ef4 i'm not intimate how works. assume similar l2s better entity support. take grain of salt.
to clear, property convenience , i'm 90% sure ef react badly if try query database using property. ef doesn't know property , cannot use construct sql. this:
var foo = x in db.foos x.hurrenum == hurr.durr select x;
will fail behave expected this:
var foo = db.foos.where(x=> x.hurrenum == hurr.durr);
probably result in entire foos table being brought memory , parsed. this property convenience , should used after database has been hit! such as:
// executed in sql server var foo = db.foos.where(x=> x.hurr == 1 || x.hurr == 2).toarray(); // done in memory var hurrfoos = foo.where(x=> x.hurrenum == hurr.durr);
if don't understand difference here you're playing fire. need learn how ef/l2s interprets code , converts sql statements.
Comments
Post a Comment