locked
Is it ok to copy an entity for reuse in EF RRS feed

  • Question

  • Hi, I'm migrating a legacy desktop application to MVC and I'm having trouble understanding a couple of EF concepts. Here is what I have going on. I'm creating an internal company Logistics application so employees can make requests for purchases. In my SQL database that I am using to create my Model from I have a table that holds Purchase Requests . The table has several fields that contain Employee Numbers such as Requestor, Buyer, Approver, etc. I have one SQL view that pulls Employee information from an Employees table (which is located in another database, Human Resources). In the legacy application I use as many Joins to the Employees view as needed for the Stored Procedure. I'll provide an example for clarity here.

    Select pr.PuchaseRequestID,pr.RequestDate, r.LastName as Requestor, b.LastName as Buyer

    FROM PurchaseRequest pr

    JOIN

    HumanResources.dbo.v_Employees r ON r.EmployeeNumber = pr.Requestor

    LEFT OUTER JOIN

    HumanResources.dbo.v_Employees b ON b.EmployeeNumber = pr.Buyer

    So now I'm learning EF and not sure how to go about bringing this same functionality to an MVC application. I have seen that I can Copy and Paste the view in the EF Designer but I have no idea of how to associate the view with the PurchaseRequest entity or if that is even an accptable method. Most examples I have seen are very basic and don't address this functionallity. I hope I have given enough information, any help would be appreciated.


    • Edited by AkAlan Saturday, May 12, 2012 10:04 PM
    Saturday, May 12, 2012 10:04 PM

Answers

  • Hi AkAlan,

    Welcome to MSDN Forum.

    If the stored procedure has already exist, you can import it as a function into Entity Framework, then you can call it like a method. Below is a tutorial about how to use stored procedure in Entity Framework, please refer to it. If you have any problem, please feel free to let me know.

    Using a Stored Procedure in Entity Framework 4

    Don't care how many views or tables are joined in the stored procedure, what you only need to do is to make sure the necessary tables and views have already added into the designer, so Entity Framework can help you to map the tables and views.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Allen_MSDN Monday, May 21, 2012 3:18 AM
    Sunday, May 13, 2012 1:36 PM

All replies

  • Hi AkAlan,

    Welcome to MSDN Forum.

    If the stored procedure has already exist, you can import it as a function into Entity Framework, then you can call it like a method. Below is a tutorial about how to use stored procedure in Entity Framework, please refer to it. If you have any problem, please feel free to let me know.

    Using a Stored Procedure in Entity Framework 4

    Don't care how many views or tables are joined in the stored procedure, what you only need to do is to make sure the necessary tables and views have already added into the designer, so Entity Framework can help you to map the tables and views.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Allen_MSDN Monday, May 21, 2012 3:18 AM
    Sunday, May 13, 2012 1:36 PM
  • Hi AkAlan,

    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.

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 16, 2012 2:31 AM