views:

33

answers:

2

I have an entity in my EDMX that I've extended with a few fields in a partial class like this:

public partial class Employee
{ 
     public string JobName {get;set;} 
} 

These properties are for display only. In the above example say the entity has a JobTypeID property. I wish JobName to be populated w/ the name that belongs to that JobTypeID.

Is there anyway to query the employee record in EF including the value for the JobName property w/o explicity assigning each field using select()?

The reason I ask is that there are a lot of fields in the Employee entity so I'd like to be able to take advantage of something like:

ctx.Employees.Where(e=>e.EmployeeID==employeeID).Single()

...add somehow fill in JobName too

Is this possible?

+3  A: 

How about: public string JobName { get { return this.JobType.Name; } }?

Stephen Cleary
Well, that works if I "include" the JobType table but that rather defeats the point of the JobName Property I added. My idea was to NOT pull down entire entire rows just to get a single field from them.
I thought about it for a bit, and I don't think EF supports column selection directly (other than as an optimization when projecting). It is an *entity* framework.
Stephen Cleary
A: 

Not a solution, but a different approach to what you are trying to achieve...
Why not use the power of EF! use "Include" to load the relation based records from related tables?

You can do that in a single place as well, say if you want a JobType record per Employee record, you may consider using a repository pattern and add all possible includes for your entities which depend on each other!

Some thoughts further on what I mentioned, not exactly as I said but...
http://mosesofegypt.net/post/Introducing-DataLoadOptions-for-Entity-Framework-ObjectContext.aspx

System.ArgumentException