Fetching multiple records from multiple tables using stored procedure in Entity Framework in ASP.NET MVC 5 - asp.net-mvc

create procedure GetCityArea
as
begin
select * from CityMaster;
select * from Area;
End
This is my stored procedure GetCityArea which returns multiple record.
My exact problem is I am getting multiple record from the stored procedure, and I want to show this result in single view as separate tables. I am new in ASP.NET MVC and I want to solve this problem using Entity Framework. Please help.

You can do this using ObjectContext and the Translate method.
The gory details are here: https://msdn.microsoft.com/en-us/data/jj691402.aspx

Related

MVC - Select from Stored Procedure in Entity Framework

I am new to ASP.NET MVC. I should create a page where users enters an order for their shops by central warehouse. The products and amounts are listed by a stored procedure from database. I have to show rows in a gridview which are calculated by the stored procedure. I want to insert the changed data in a table in SQL after the user make changes on the gridview. Users can call the saved doc back and make changes on it and save it again.
I can't build a strategy how that can be made. If I use Entity Framework I can show the SQL table rows in grid but it is not my goal. I have to let the SQL calculate first the data. Could you please give me some start point and steps to go ahead. I hope I could explain what I need.
There Are some simple steps to do that
1- Go and update model from database and add the required Stored procedure
2- create a complex type from model browser
in complex type map your Stored procedure fields as it returns the data.
3- and map that complex type to the stored procedure. and use it as you use table.

MVC Entity Framework calling stored procedure

I am using ASP.NET MVC 4.5 and EF. I import the stored procedures into my ADO.NET Entity Data Model. I have my .edmx and XX.tt with my StoreProcedure_Result.cs.
I use
var result = dbcontext.SP(Param).AsEnumerable().First();
My problem is that those stored procedures that have
select count(id) as Count from table
doesn't appear on my SP_Result.cs
Any ideas?
I just tried this out myself and did not see a "_Result.cs" class created either for the sproc that just returns count(). I'm guessing that a _Result.cs class does not need to be created because it is just a single int, and a specific type is not needed. I was still able to call the sproc though. You could obtain the int like this...
var result = db.getCount().First();
int i = (int)result;

Multiple select statements in a stored procedure for use in classic ASP

Currently I have a classic asp application, and one of the page has logic like this:
SELECT * FROM Table1 WHERE Condition
//DO stuff
SELECT * FROM Table2 WHERE Condition
//DO stuff
SELECT * FROM Table3 WHERE Condition
//Execute
I need to convert this into a stored procedure. Now I know how to use stored procedures in ASP generally, but I don't know how to do it with multiple selects. How can I generate three sets of data and use them properly?
Thanks.
Are you using ADO or ADO.Net ? Both have the capability to return multiple recordsets from a stored procedure. In Ado, if a stored procedure has multiple Selects in it, you can access the second, and subsequent Resultsets (ADO RecordSets) in your client code by calling Recordset.NextRecordSet.
In ADO.Net, When a Stored proc has multiple Selects, ADO.Net will put the results of each Select into a DataTable object, and put each DataTable into the Tables collection of the DataSet object which returned by the ADO.Net command.Execute() method.

How to access Stored procedure in Code First Model which return 6 or 7 table combine result

i am new in MVC and entity frame work and i want to create Code first entity frame work.
we have already created project in asp.net and we want to migrate in mvc. we have lots of stored procedure and some procedure return complex data combination of 10 to 12 tables...
As a Proof of Concept we wan't to develop 3 to 4 pages...
i have some question regarding new start.
1) Should i used entity frame work if yes then which is better entity frame work model
Database first
Model first
code first
2) how to integrate stored procedure in Code first model
3) in each page we have minimum 7 to 8 table result there... how i will handle in entity frame work.
this is my first project in mvc and entity framework please help me with appropriated answer.
first, this has nothing to do with MVC. this is purely a data access issue.
second, this is sort of missing the point of using entity framework. if the goal is to migrate away from stored procs that one thing, but to use EF and continue to execute the stored procs defeats the purpose of using a ORM like EF.
Instead for your procs I would stick with raw ADO.Net, or use Dapper.Net to convert the stored proc result sets into objects.
EF would be a better choice as your convert each proc into EF linq queries. It's not that you can't execute procs (or raw sql) from EF, but it doesn't make much sense. Especially with how you describe the procs.

How to call stored procedure with input parameters in ADO.NET Entity Framework 4 in ASP.NET 4.0

I am using Database first modal and EF4.0.
I have created a stored procedure which required two input parameters and return dynamically column in result-set i.e. columns are not fixed in result.It may be 5 or 7 or 10 and so on.
I am using Grid-view and passing the result-set in it's data-source.
How can i call stored procedure in this case.
thanks.
You must use ADO.NET and data reader / data adapter directly. EF can work only with stored procedures producing strongly typed results known at design time (you must create class for them).

Resources