I’m not sure if I should work directly with the EntityObject, or if I should make som wrapper methods for selecting, updating and deleting EntityObjects? I would like to use the last option, but I can’t really figure out how to return an EntityObject (so I still can call context.SaveChanges();) and not for example a List<Worker> (which is stupid since I can’t make changes to the Workers in the list and then easily submit the chages to the database.
For example, I have a Worker table. I could get a worker by using my context:
var worker = context.Worker.Where(w => w.WorkerID == 1).FirstOrDefault();
Or, I could create a wrapper method:
public static RETURNTYPE GetWorkerByID(int id, context)
{
var worker = context.Worker.Where(w => w.WorkerID == 1).FirstOrDefault();
return worker;
}
What kind of returntype should I work with, if I still wish to work with the context (allowing me to alter the data)?
Thanks!
If you make a wrapper type you will not be able to use it with context anymore. Using wrapper means that your return type will represent a new instance filled from the entity object and when you push that instance back you will again need to create / fill entity object to work with.
Have you considered using POCOs (EF 4.0 and newer only)? That would solve your problem because there is on
EntityObjectbase class.