locked
Stored Procedure in EF RRS feed

  • Question

  • Hello - I am fairly new in EF. My question is about store procedure and custom entity. My scenario is I have stored procedure named "GetItem", I created function import out of it and choose the return collection of "Items" (which is a custom entity set). The stored procedure will just return all the available items and populate it into Assets entity. When I am compiling I am receiving and error of Entity type 'Items' is not mapped. The "Items" is not connected to any existing table it is just DTO for my GetItems stored procedure. Any suggestions?

    Friday, September 17, 2010 9:37 PM

Answers

  • On 9/17/2010 5:37 PM, maridob wrote:
    > Hello - I am fairly new in EF. My question is about store procedure and
    > custom entity. My scenario is I have stored procedure named "GetItem", I
    > created function import out of it and choose the return collection of
    > "Items" (which is a custom entity set). The stored procedure will just
    > return all the available items and populate it into Assets entity. When
    > I am compiling I am receiving and error of Entity type 'Items' is not
    > mapped. The "Items" is not connected to any existing table it is just
    > DTO for my GetItems stored procedure. Any suggestions?
    >
     
    The sproc used by Entity Framework must be mapped to an entity on the
    conceptual model.
     
    If you're going to use a sproc with EF, then you should use Entity SQL
    in the sproc and not T-SQL, which must be used with an entity or
    entities on the conceptual model.
     
    http://msdn.microsoft.com/en-us/library/bb387145.aspx
    http://msdn.microsoft.com/en-us/library/bb387118.aspx
    http://www.informit.com/articles/article.aspx?p=1273361&seqNum=3
     
    You can execute ESQL in-line code and use the ESQL datareader to read
    the return result or results and populate your DTO from the datareader
    in your project.
     
    You can just use ADO.NET SQL Command object to execute the sproc and use
    a datareader to populate the DTO the traditional way without the EF in
    your project.
     
    You can use the EF way and the SQL Command object (traditional way)
    combined to execute the sproc with T-SQL and using a datareader to
    populate the DTO if you insist on using T-SQL and by using the EF
    backdoor in your project.
     
    <http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx>
     
    <http://blogs.msdn.com/b/alexj/archive/2009/03/26/index-of-tips.aspx>
     
     
    While in the datareader loop, you populate the DTO and load the DTO
    into a List<T>/List<DTO> and return the collection of DTOs.
     
     
     
     
     
    Friday, September 17, 2010 10:36 PM

All replies

  • On 9/17/2010 5:37 PM, maridob wrote:
    > Hello - I am fairly new in EF. My question is about store procedure and
    > custom entity. My scenario is I have stored procedure named "GetItem", I
    > created function import out of it and choose the return collection of
    > "Items" (which is a custom entity set). The stored procedure will just
    > return all the available items and populate it into Assets entity. When
    > I am compiling I am receiving and error of Entity type 'Items' is not
    > mapped. The "Items" is not connected to any existing table it is just
    > DTO for my GetItems stored procedure. Any suggestions?
    >
     
    The sproc used by Entity Framework must be mapped to an entity on the
    conceptual model.
     
    If you're going to use a sproc with EF, then you should use Entity SQL
    in the sproc and not T-SQL, which must be used with an entity or
    entities on the conceptual model.
     
    http://msdn.microsoft.com/en-us/library/bb387145.aspx
    http://msdn.microsoft.com/en-us/library/bb387118.aspx
    http://www.informit.com/articles/article.aspx?p=1273361&seqNum=3
     
    You can execute ESQL in-line code and use the ESQL datareader to read
    the return result or results and populate your DTO from the datareader
    in your project.
     
    You can just use ADO.NET SQL Command object to execute the sproc and use
    a datareader to populate the DTO the traditional way without the EF in
    your project.
     
    You can use the EF way and the SQL Command object (traditional way)
    combined to execute the sproc with T-SQL and using a datareader to
    populate the DTO if you insist on using T-SQL and by using the EF
    backdoor in your project.
     
    <http://blogs.msdn.com/b/alexj/archive/2009/11/07/tip-41-how-to-execute-t-sql-directly-against-the-database.aspx>
     
    <http://blogs.msdn.com/b/alexj/archive/2009/03/26/index-of-tips.aspx>
     
     
    While in the datareader loop, you populate the DTO and load the DTO
    into a List<T>/List<DTO> and return the collection of DTOs.
     
     
     
     
     
    Friday, September 17, 2010 10:36 PM
  • Hi,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, September 22, 2010 5:44 AM