Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to generate function import return type of the store function

I have the following simple saved as a scalar function in my SQLEXPRESS (generated via Visual Studio) and running it via VS as a SQLQuery1.sql works just fine.

CREATE FUNCTION [dbo].[AveragePurchase]
(
@CustomerID int
)
RETURNS DECIMAL(8,3)
AS
BEGIN
DECLARE @Average DECIMAL(8,3)
SELECT @Average = avg(PurchaseAmount)
FROM Purchases1
WHERE CustomersCustomerID = @CustomerID;
RETURN @Average
END

I them go to update the model from the database and run the wizard having checked the function to tell the VS to incorporate it into the model. I seem to be running into the following warning:

Warning 1 Error 6046: Unable to generate function import return type of the store function 'AveragePurchase'. The store function will be ignored and the function import will not be generated.

I must be overlooking something quite obvious but can't seem to locate how I can correct what it is complaining about. any help appreciated. thanks!

like image 773
Yan D Avatar asked May 30 '14 17:05

Yan D


1 Answers

Running into same issue and found this answer from microsoft.

For the scalar UDF, unfortunately, it is not supported by default even in Entity Framework 6 or 6.1. One way to use it in Entity Framework is to create a stored procedure using your scalar UDF and call the stored procedure in your project.

source: microsoft msdn

like image 164
MattOpen Avatar answered Oct 24 '22 11:10

MattOpen