Bind variables, Select after Insert, Fetching entity projections

Posts   
 
    
steve2
User
Posts: 1
Joined: 29-May-2007
# Posted on: 29-May-2007 21:14:55   

Three questions:

(1) The default for generated SELECT statements is to use Bind variables via sp_executesql (e.g. when a filter is used in FetchEntityCollection). This is great for INSERT's where you generally want to reuse the access plan and for filters on columns with uniform data distributions but this can be a problem for skewed data in large tables where different access plans are needed for different literals. Is there any way to override the use of Bind variables?

(2) Whenever an INSERT is generated, a SELECT is also generated. Is this to read back the row in case an IDENTITY value was generated? Is there any way to turn this off?

(3) The FetchEntity and FetchEntityCollection classes always fetch all columns of the result set. There appears to be a way to retrieve selected columns using projections on Typed Lists; however, I can't find any way of doing this for Entities. Is there a way?

Thanks, Steve

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 29-May-2007 22:41:35   
  • I dont' know
  • the default is to refetch the entity(s). there is a fetch overload to prevent a refetch
  • this is by design. if you want to fetch specific fields for an entity/collection you need to use projection and project it onto an entity/collection.
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39914
Joined: 17-Aug-2003
# Posted on: 30-May-2007 15:54:48   

steve2 wrote:

Three questions:

(1) The default for generated SELECT statements is to use Bind variables via sp_executesql (e.g. when a filter is used in FetchEntityCollection). This is great for INSERT's where you generally want to reuse the access plan and for filters on columns with uniform data distributions but this can be a problem for skewed data in large tables where different access plans are needed for different literals. Is there any way to override the use of Bind variables?

No, unfortunately not, as the sp_executeSQL call is made by the SqlClient, not by us. We simply generate a SQL statement and set the command type to Text. This will the SqlCommand then perform a EXEC sp_executesql ... to preserve the execution plan.

(2) Whenever an INSERT is generated, a SELECT is also generated. Is this to read back the row in case an IDENTITY value was generated? Is there any way to turn this off?

Only when an IDENTITY field is encountered, a select takes place (but this is part of the insert query, batched, and doesn't access tables). If you've specified to refetch the row after insert, it is refetched of course.

(3) The FetchEntity and FetchEntityCollection classes always fetch all columns of the result set. There appears to be a way to retrieve selected columns using projections on Typed Lists; however, I can't find any way of doing this for Entities. Is there a way?

At the moment projections are the way to go. In the upcoming upgrade you will be able to exclude fields for entity fetches so you can fetch entities and say exclude a couple of fields for a given fetch call and fetch them later on.

Frans Bouma | Lead developer LLBLGen Pro