开发者

define scalar function with ef4.1 code first?

开发者 https://www.devze.com 2023-04-12 05:18 出处:网络
i have a function called distancebetween i wnat to define it in scalar valued function to call it by linq

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开发者_JS百科 first ?


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.


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号