Querying an EDM model to get collection of 2nd relation entities

  • Thread starter Thread starter MarkA
  • Start date Start date
M

MarkA

Hi, I have been using EF since it's release, for the most part, it's saved me
thousands of lines of code.

I've a scenario I havn't been able to solve with well performing code.

Imagine a model of a phone book, with Companies, Departments and People. A
company has an ID and name, department has an ID and name, and a person has
an ID and name (keeping it simple).

How can I write an entities statement which will return a collections of all
people under a company (regardless of department)?

I considered using something like this:

context.People.Where(p=>p.Department.Company.CompanyId == CompanyIdSearched)

However, my understanding is this goes back to the database to pull the data?

I need to query based on the in-memory data, so I can include data which has
changed but not yet been saved (eg. to check if I've already added a Person
in an import).

What's the most efficient way to query the in-memory context, to get all
People who work for a Company?

Thanks in advance :-)
+M
 
Hi, any assistance appreciated- I'm using a foreach iteration to build an
array- I expect there will be a smarter way using LINQ to entities?

Thanks,
+M
 
The entity framework, linq, dlinq, datasets in the .NET framework are
all "hacks" made for idiots that have no idea about architecture,
design, databases, application requirements process. Instead, the
idiots write their applications using these "hacks" so that after a
couple of months, it displays "Application not Responding" and "Server
timeout" messages.

Get a beginners level book on application architecture, database
design, and application design. A hybrid developer (one that knows
about writing applications and SQL) is much better than an idiot that
uses ORMs and "RAD" tools.
 
Back
Top