This project has moved and is read-only. For the latest updates, please go here.

Generate Store Procedure

May 22, 2014 at 10:01 PM
Edited May 22, 2014 at 10:15 PM
Hello great project
my question is I ENTITIES generates well with pocoentityCodeFirst
but my question is how can I do that I generate entities and once I generate the stored procedures in the schema for me and displays them but does not generate me thanks
May 23, 2014 at 7:42 AM
You can write C# code for stored procedures by setting codeWriterSettings.WriteStoredProcedures = true

The generated stored procedures use raw ADO whatever the CodeTarget. It doesn't write Code First Database.SqlQuery<T>(parameters) type code - it uses raw ADO. When I use this style (or dapper), I use the generated xResult class (the output) and I copy the signature of the generated stored procedure Execute method (input). This saves the labor-intensive code.

Using stored procedures with the syntax DbSet.SqlQuery("x @p",z) works fine.

It doesn't support the EF 6 MapToStoredProcedures functionality, because recognizing the Insert/Update/Delete stored procedures would be a little complicated. If you follow the EF conventions, it's trivial to map manually.
May 23, 2014 at 1:54 PM
Hi if the stored procedure generates me the truth but I'm a bit newbie in c # and have not found how to execute the stored procedure that generates dbschemareader if I can give an example I would greatly appreciate
May 24, 2014 at 4:38 PM
So taking the example of Northwind, here's how to call the "Sales by year" procedure.
"Sales by year" has been turned into a class called "Procedures.SalesByYear" (spaces and underscores are removed to make more c#-normal names)
The output is a class called SalesByYearResult.
            //get connection from Entity Framework or build it yourself
            //var context = new NorthwindContext();
            //var connection = context.Database.Connection;
            using (
                var connection =
                    new SqlConnection(@"Data Source=.\SQLEXPRESS;Integrated Security=true;Initial Catalog=Northwind"))
            {
                //create the stored procedure proxy
                var proc = new SalesByYear(connection);
                //execute it with the input parameters
                var result = proc.Execute(new DateTime(1998, 1, 1), new DateTime(1999, 12, 31));
                //user the result class
                foreach (var salesByYearResult in result)
                {
                    Console.WriteLine(salesByYearResult.OrderId + " " + salesByYearResult.Subtotal);
                }
            }