1

i have a function called distancebetween i wnat to define it in scalar valued function to call it by linq if there is away to do that by EF4.1 code first ?

Faust
  • 15,130
  • 9
  • 54
  • 111
Khalid Omar
  • 2,353
  • 5
  • 35
  • 46

2 Answers2

1

No. Code first was designed as "code first" = you will create a code and it will create a database where no database logic exists (no views, stored procedures, triggers or functions). Because of that it is completely missing features for mapping database logic like functions and stored procedures. If you want to use it in LINQ you must abandon code-first / fluent-API and start tu use EDMX where this is supported.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Thank you do you think that they may support that in future releases of ef – Khalid Omar Oct 11 '11 at 10:07
  • Sorry, I don't know that and I didn't read about that anywhere. You can check if it is already requested on [UserVoice](http://data.uservoice.com/forums/72025-ado-net-entity-framework-ef-feature-suggestions) – Ladislav Mrnka Oct 11 '11 at 10:10
0

Using ExecuteSqlCommand and an output parameter should do the trick for scalar stored procs

var outParam = new SqlParameter("overHours", SqlDbType.Int);
outParam.Direction = ParameterDirection.Output;

var data = context.Database.ExecuteSqlCommand("dbo.sp_getNumberJobs @overHours OUT", outParam);
int numJobs = (int)outParam.Value;
atreeon
  • 21,799
  • 13
  • 85
  • 104