如何在使用EF从sql server调用用户定义的函数时使用Aggregate属性 [英] How to use Aggregate property when calling an User defined function from sql server using EF

查看:134
本文介绍了如何在使用EF从sql server调用用户定义的函数时使用Aggregate属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当我的udf有条件地给出一些聚合值和一些标量值时,如何使用Aggregae属性。请告诉我如何使用下面的Udf聚合。

I want to know how to use the Aggregae property when my udf is conditionally giving some times aggregate values and some times scalar values. Please tell me how to use the Aggregate for below Udf.

ALTER FUNCTION dbo.Function1
(
@TabelName varchar(20)
)
RETURNS int
AS
BEGIN
DECLARE @SQL VARCHAR(1000) ;DECLARE @avg INT;
--SET @SQL='SELECT * FROM movies'--+ @TabelName;
--print @SQL ;
--EXEC sp_Executesql @SQL ;
if(@TabelName='Movies')
begin
SELECT @avg=COUNT(*) FROM MOVIES;
end
else
select @avg=100;
return @avg;
END



 

 

 

推荐答案

您是如何尝试使用EF的?由于函数接受标量参数并返回标量,因此您应该能够像使用任何其他UDF一样使用它。你遇到了什么问题?

How are you trying to use it from EF? Since the function takes in a scalar parameter and returns a scalar, you should be able to use it like any other UDF. What problems are you facing?

谢谢

Srikanth


这篇关于如何在使用EF从sql server调用用户定义的函数时使用Aggregate属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆