views:

923

answers:

4

Hi there,

Is it true that you cannot call an sp with the EF unless the sp returns an entity?

To test I created 3 Function Imports for an sp with 1. no return type 2. a scalar return type and 3. an entity return type

then when i type "DataContext" then "." I only get intellisense on the function that returns an entity!

I'm surprised this isn't a current feature!

What are people using as a workaround?

A: 

Has to return an entity, yes.

OwenWiseman
+1  A: 

There is a workaround!

Julie Lerman wrote a post about this. Have a look at her blog: http://thedatafarm.com/blog/data-access/implement-select-stored-procedures-that-return-miscellaneous-data-in-ctp2-of-ef-designer/

It helped me a lot to implement my stored procedures.

Chrigl
A: 

Using powerful T4 templates

Entity Framework V1.0 feels and is an unfinished product set out to public too early. That's why it's possible to use T4 templates that create different code from EDMX files, that also supports scalar-type stored procedures.

We're using custom templates with lots of modifications so they create Business layer objects, interfaces for IoC/TDD as well as DAL and DAO. We get everything from EDMX files. Heck we even create enums but those are created from real data in the DB not EDMX files.

You'll be able to find lots of T4 templates... Here's one that does scalar stored procedures. But you may want to get one that actually does POCO.

Robert Koritnik
A: 

In EF v1 you can only map procedures which return entities. In EF v4 you can map procedure results to complex types, so most procedures can be used without returning entities.

Use Chrigl's answer (+1) as a workaround for v1.

Craig Stuntz