How to create asp.net MVC database first with stored procedure?

309 views Asked by At

I have an Oracle database which contains some tables with no foreign or primary keys on them. I will create some stored procedures to handle the interaction with these tables, takes some parameter and return some values.

I would like to create an asp.net MVC app using EF and deal with this database using only the stored procedures. I don't want to bring any of the tables to the app as entities or anything.

I have been googling this, but all I can find is examples where the tables(entities) themselves are in the EDM and the stored procedures are being added to them for the interaction.

EX:

enter image description here

Is it possible to get the EF to deal with stored procedures only and provide me with models based on these stored procedures? if yes would you please direct me to the right materials?

Thanks,

1

There are 1 answers

0
ArDumez On

You can use ExecuteStoreQueryList or equivalent on dbContext directly, create dto model result returned. A sample:

using (var ctx = DataContext())
{
    return ctx.ExecuteStoreQueryList<MyModel>(
        "EXEC dbo.[xxx] @xxx, @xxx, @xxx, @poleID, @xxx",
        new SqlParameter("xxx", xxx),
        new SqlParameter("xxx", xxx),
        new SqlParameter("xxx", (object)xxx?? DBNull.Value),
        new SqlParameter("xxx", (object)xxx?? DBNull.Value),
        new SqlParameter("xxx", (object)xxx?? DBNull.Value)
    );
}