views:

229

answers:

1

I have a LINQ to SQL entity called Job which is just a simple table in SQL. Most of the time it works for what I need but occasionally I need more fields to be populated in this entity. I know I can use partial classes to add new fields to the LINQ generated class, but my question is how do I populate this extra data? For example, I have a stored proc that pulls back all the values for the Job table and the extra data I need to populate. I'd like to hook into the entity populate routines and when this data is present, populate it, when it's not, ignore it. I know the simple solution is to create a view, but I don't like that solution.

I can't seem to figure out where LINQ is taking the data and populating the entity. Does anyone have any ideas?

Thanks!

A: 

(wild guess) you may be able to create an entity from a SQL view. create the view in the db with the joins etc, like in the SP, then add that view to the LINQ designer and it should create an entity with all the gear u need.

OR

(better) Create a class that represents your complete entity (with optional fields) and map to the many entites (you presently have) as another step in the process. This longer coz you will prob want to create another layer of abstraction to do this.. and then to take it further you will prob want to abstract your whole entity set, etc etc.. So its more work.. but it brings you closer to a cleaner Domain Model (if that's what you want).

cottsak
Yeah, I don't like solution one because it adds extra entities.The problem with solution two is it requires me to query my database twice, something I was hoping to avoid.
the second option does not require 2 sql queries. in this example you would create a mapping to the LINQ entities within the -same datacontext-. LINQ would then create the appropriate joins etc in the single sql query.
cottsak