views:

123

answers:

1

Hi

Is it possible to materialize (within the Entity Framework) Entities from a standard SQL Data Reader?

I am writing specific SQL that is passed to the server using EntityConnection.StoreConnection. Thsi returns a standard Data Reader containing rows should be materialized as Entities.

I suppose one workaround is to create a Entity-returning Function Import that can run my arbitrary SQL, but I wonder if there is a neater way?

Regards

Lee

A: 

If you want to specify custom SQL for your entity results, you should use either a defining query (see also) (supported by the EF, but not the GUI designer, at least in v1) or a stored proc.

Update: In EF v4, you can use ExecuteStoreQuery<T> and get materialization of arbitrary entities for free.

Craig Stuntz
There are two problems with that method:1) I would have to create a new type of Entity - I want to create materialize entities of the type I already have.2) It looks as though I cannot specvify the defining query dynamically
Lee Atkinson
You can pass SQL (or a fragment thereof) to a proc.
Craig Stuntz