开发者

Using entity framework with Stored procedures and unnamed columns

开发者 https://www.devze.com 2023-04-10 10:05 出处:网络
I am trying here to work with entity framework with unnamed columns within a stored procedure. Say for instance the following SP :

I am trying here to work with entity framework with unnamed columns within a stored procedure.

Say for instance the following SP :

CREATE PROCEDURE [dbo].[GetUsers]
AS
BEGIN

    SELECT 
        Username, 
     开发者_开发问答   Firstname + ' ' + Lastname
    FROM
        dbo.users

END
GO

Normally if I create a mapping in entity framework I have 2 columns in a complex object created (Username and Column1).

The problem here is I try to use POCOs instead of auto-generated complex objects.

With named columns the reflexion does the job. But when I include concatenated column It is not mapping the data. Is it possible to map it in any kind of way to an existing POCO [having Username and Fullname as existing properties for instance] ? (attributes, wizard or something else ?)


Auto-generated objects are still POCOs if you use correct template so you can map procedure as function import and use complex type. Otherwise use what @marc_s suggested and give every computed column alias:

SELECT 
    Username, 
    Firstname + ' ' + Lastname AS FullName
FROM
    dbo.users
0

精彩评论

暂无评论...
验证码 换一张
取 消