locked
Stored Procedure call in entity Framework RRS feed

  • Question

  • How to call a Stored procedure in entity framework in silverlight 3.

    I want to call a stored procedure that is not particularly related to any one entity. I can't use function mapping since i don't have the all three insert, update, delete stored procedures

    I found this code on another post but I can't add the reference of System.Data.Entity to my project becasue I get an error "System.Data.Entity dll was not build against silverlight runtime"

    public void MyMethod(int productID)

    {

        using (EntityConnection connection = new EntityConnection(Connection.ConnectionString))

        {

            connection.Open();

            EntityCommand command = connection.CreateCommand();

            command.CommandText = "NorthwindEFEntities.MySPName";

            command.CommandType = CommandType.StoredProcedure;

            command.Parameters.AddWithValue("ProductID", productID);

            try

            {

                command.ExecuteNonQuery();

            }

            finally

            {

                connection.Close();

            }

        }

    }

    Wednesday, September 16, 2009 8:27 PM

Answers

  • Thanks for correcting me Syed.

    I ended up creating a wcf service that provides and operation to call the stored procedure.
    • Marked as answer by Yichun_Feng Monday, September 21, 2009 7:32 AM
    Thursday, September 17, 2009 4:30 PM

All replies

  • Hi,

    Are you trying to reference System.Data.Entity.dll in your silverlight project? Notice that the code you posted is to be placed at server side and you need to invoke it from silverlight client using WCF/Web/RIA Service.

    Hope that helps.

    Regards,
    Syed Mehroz Alam
    My Blog | My Articles
    • Proposed as answer by Syed Mehroz Alam Thursday, September 17, 2009 6:26 PM
    • Marked as answer by Yichun_Feng Monday, September 21, 2009 7:32 AM
    • Unmarked as answer by Yichun_Feng Monday, September 21, 2009 7:32 AM
    Thursday, September 17, 2009 3:24 AM
  • Thanks for correcting me Syed.

    I ended up creating a wcf service that provides and operation to call the stored procedure.
    • Marked as answer by Yichun_Feng Monday, September 21, 2009 7:32 AM
    Thursday, September 17, 2009 4:30 PM