Return value mapping on Stored Procedures in Entity Framework
- by Yucel
Hi, I am calling a stored procedure with EntityFramework. But custom property that i set in partial entity class is null.
I have Entities in my edmx (I called edmx i dont know what to call for this). For example I have a "User" table in my database and so i have a "User" class on my Entity.
I have a stored procedure called GetUserById(@userId) and in this stored procedure i am writing a basic sql statement like below
"SELECT * FROM Users WHERE Id=@userId"
in my edmx i make a function import to call this stored procedure and set its return value to Entities (also select User from dropdownlist). It works perfectly when i call my stored procedure like below
User user = Context.SP_GetUserById(123456);
But i add a custom new column to stored procedure to return one more column like below
SELECT *, dbo.ConcatRoles(U.Id) AS RolesAsString
FROM membership.[User] U
WHERE Id = @id
Now when i execute it from SSMS new column called RolesAsString appear in result.
To work this on entity framework i added a new property called RolesAsString to my User class like below.
public partial class User
{
public string RolesAsString{ get; set; }
}
But this field isnt filled by stored procedure when i call it.
I look to the Mapping Detail windows of my SP_GetUserById there isnt a mapping on this window. I want to add but window is read only i cant map it. I looked to the source of edmx cant find anything about mapping of SP.
How can i map this custom field?