Return value mapping on Stored Procedures in Entity Framework

Posted by Yucel on Stack Overflow See other posts from Stack Overflow or by Yucel
Published on 2010-12-23T17:16:32Z Indexed on 2010/12/24 4:54 UTC
Read the original article Hit count: 228

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about stored-procedures