Search code examples
c#sqlentity-frameworkado.net-entity-data-model

Fake query in Entity Framework


How we drag drop Fake query procedure in ADO.Entity Framework

e.g: I have SP

Select col into #temp from Table

Error:

Entity framework does not make the return type of this SP.


Solution

  • I also had similar problem i used following approach.

    First write your SP and than declare as many variables as your SP will return columns at end of sp and than write a select statement which will select all variables as columns hence EF will find return type of SP. Before dragging SP comment out the actual code of sp and only write the select statement. When you have dragged the SP comment the select statement written at end and ucomment actual code of SP.

    Example

    Create Procedure TestSP
    Select col into #temp from Table
    select col from #temp
    //This is fake Query
    Declare @colName DataType
    Select @colName as colName
    

    Now before dragging the sp comment following lines

    Select col into #temp from Table
    select col from #temp
    

    And after dragging the sp uncomment the above lines and comment following lines

    Declare @colName DataType
    Select @colName as colName
    

    This way EF will find return type.

    NOTE This is only for one column if your SP returns let say 3 columns you have to declare 3 variables and than select these 3 variables as columns.