I am using EF4 and I used the POCO entity generator to create my entities. I have a stored procedure called UpdateApplicationState. I pass it just 2 parameters called ApplicationID and ApplicationStateID. It returns nothing so I set the return type as None. I only want it to update the application state ID, nothing else. When I create my function import for this stored procedure then I don't see it in my context file under "Function Imports". Why is this? Is it then created on another place? How would I call this method?
EDIT:
Is there no one here that canhelp me here? All that I want to do is to call this import function (which is not in the context) like I do my other import functions in my repository class:
public void UpdateAppl开发者_JAVA百科icationState(int applicationID, int applicationStateID)
{
context.UpdateApplicationState(applicationID, applicationStateID);
}
And from my view:
applicationRepository.UpdateApplicationState(id, newApplicationStateID);
Here is my stored procedure:
ALTER PROCEDURE [dbo].[UpdateApplicationState]
(
@ApplicationID INT,
@ApplicationStateID INT
)
AS
BEGIN
UPDATE
[Application]
SET
ApplicationStateID = @ApplicationStateID
WHERE
ApplicationID = @ApplicationID;
END
Thanks
The problem is that the template provided with EF4 POCO does not handle function imports that have no return type. You can either set a scalar return type, or you can modify the YourProject.Context.tt file to fix the problem.
Look in the file for the section starting with:
region.Begin("Function Imports");
Then a bit further you will see a code block like this:
if (edmFunction.ReturnParameter == null)
{
continue;
}
string returnTypeElement = code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));
You can replace that with the following:
string returnTypeElement = edmFunction.ReturnParameter == null
? null : code.Escape(ef.GetElementType(edmFunction.ReturnParameter.TypeUsage));
Then look for the two usages of returnTypeElement
in the next few lines. The first is in the method definition:
<#=Accessibility.ForMethod(edmFunction)#> ObjectResult<<#=returnTypeElement#>>
Replace with:
<#=Accessibility.ForMethod(edmFunction)#> <#= returnTypeElement == null ? "int" : ("ObjectResult<" + returnTypeElement + ">") #>
The next is a few more lines down in the return statement:
return base.ExecuteFunction<<#=returnTypeElement#>>
Replace with:
return base.ExecuteFunction<#= returnTypeElement == null ? "" : ("<" + returnTypeElement + ">")#>
Now you should find that it properly generates the methods for the function imports. Perhaps the EF4 team will pick up on this and make the modifications for us in the next version.
精彩评论