none
About Entity Framework code first RRS feed

  • Question

  • CREATE PROCEDURE [dbo].[GetBlog]
    AS
    BEGIN
        select a, b, c
        from data
    END


    How whould you write the code in order to retrieve a big list (Ilist<Blog>) from the SP GetBlog in relation to Raw SQL ?

    Thank you!
    Wednesday, April 12, 2017 2:10 PM

Answers

  • Hi,

    You could create a custom models like this:

    public class QueryBlog
        {
            public int a{ get; set; }
    
            public string b{ get; set; }
    
            public string c{ get; set; }
        }

    Then Query the result like this:

    var query = db.Database.SqlQuery<QueryBlog>("GetBlog");
                    foreach (var item in query)
                    {
                        Console.WriteLine("{0}  -- {1}  -- {2}", item.BlogId, item.Name, item.Url);
                    }

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Sakura Data Sunday, April 16, 2017 3:52 PM
    Thursday, April 13, 2017 6:07 AM
    Moderator