Using dbml with stored procedures in MVC - asp.net-mvc

I had created a project in MVC using Webforms.I need to include dbml with stored procedures in MVC.I am new to MVC and I know that I need to create the dbml and call those in model.
I do not know how to implement it.Please send me a sample project in MVC having stored procedures in dbml.
Any url please.
Regards
S.Guhananth

So, since you mention dbml, we know you use Linq to SQL. It has really nothing to do with MVC, as you can use Linq to SQL with any front end technology. Here is the sample tutorial:
http://dodgenotes.blogspot.ca/2012/02/how-to-create-dbml-and-invoke-stored.html

Related

Call stored procedure in asp.net MVC 5 for existing database and stored procedure in SQL server

I have the existing database with tables, views and stored procedures in SQL Server. I am looking for ways to call and execute this stored procedures in either ASP.NET MVC 5 web application or ASP.NET core. I saw various ways using Entity framework and ADO.net on the internet, but always got somewhere struck. Can someone please tell me the best way to deal this scenario. Also, note I need to use the existing stored procedure as whole business logic is already done in stored procedures.My completely new to ASP.NET so any suggestions regarding what technology, frameworks or tools to use will be a great help.

How to call stored procedures from mvc3?

I'm trying to use mvc3. The online documentation says how to connect one class to one table. anybody have a suggestion on how to run stored procedures and return the results to a view?
MVC is not responsible for the way you access your data. There are many technologies that you can use including
Plain old ADO.NET
LINQ to SQL
NHibernate
Entity Framework
LINQ to SQL is probably the easiest way to get it working without any prior knowledge. Check out Scott Gu's post http://weblogs.asp.net/scottgu/archive/2007/08/16/linq-to-sql-part-6-retrieving-data-using-stored-procedures.aspx

Asp.net MVC with SQL Server stored Procedure

I am an asp.net webforms developer and new to asp.net MVC....
Is it possible to use SQL Server 2005 stored procedures in asp.net MVC?? If so can any one help me....
This is absolutely possible. Although it claims to be a Model View Controller framework, ASP.NET MVC is really just View Controller, it's up to you the developer to decide and implement a model persistence layer.
As a WebForms developer you're likely familiar with DataSets, however these are usually avoided in an ASP.NET MVC application in favour of an ORM framework like NHibernate or Linq2Sql, both of which have plenty of resources online for integration with ASP.NET MVC. As a good starting point, you might want to look at S#arp Architecture which is a good example of a best practice MVC stack.
Using stored procedures is not directly related to which type of application you are building. You could use the same type of data access code as you are used to from WebForms, such as ADO.NET (SqlConnection, SqlCommand etc.).
Absolutely agree with answers above, my advice is to use Entity framework or LINQ2SQL and simply import stored procedure as function which you can use as dbContext.Somemehto();
Stored procedure should only be linked with Model that is pure sever code, so there is no difference in using it from Desktop application or from Model. If it is not distributed database.

ASP.NET MVC + Oracle: samples and how-to

While reading NerdDinner, and browsing other examples on the internet regarding ASP.NET MVC with LINQ To SQL.
In my ASP.NET MVC project I have to connect to an Oracle database. The main goal of the application is to display, edit, and update data. I am uncertain if ASP.NET MVC can work with an Oracle database.
Has anyone ever done an ASP.NET MVC project with Oracle as the database?
Are there any articles with sample code that you'd recommend?
What are some easy ORMs or data access strategies that you'd recommend an ASP.NET (webforms or MVC) project use to communicate to an Oracle database?
You can use Nhibernate to get access to your DB.
ASP.NET MVC can certainly support Oracle or any other data source behind the scenes.
MVC is not tied to Linq to SQL in any way. It's just one convenient way (among many) to get data from a datasource into your models.
As Sly pointed out, NHibernate is one ORM framework that will work for you.

connect to DB using MVC

I have an asp.net mvc application and i need to connecto to the DB i have saw a tutorial video that connect to DB using wizard by adding DB connection and determine the DB and add a model but i need to know if i can use connection string and query the DB or calling procedures in DB ???
I need any tutorials or step by step article that describe how to connect to DB without wizard and call procedures and query tables.
Thanks in advance and i am a begineer in MVC
I hesitate to respond to this, but EVERY video you have seen is likely using an OR/M to generate the Model and the DAL. The generated DAL will likely encapsulate your calls to the stored procedures that you're asking about.
The thing is -- and here's why you're not getting the answer you're looking for -- each OR/M is going to have a different method of retrieving data from and inserting data into the database. How you retrieve data from the DB using an OR/M is going to be different if you're using Entity Framework, Linq to SQL, SubSonic, NHibernate, or any other OR/M.
So, the question is to you. Are you using a OR/M? If so, which one? If not, then you will use the standard ADO.NET calls to retrieve and store data. This is also reflected in my comment to your original question.
Yes you can (google ado.net for tutorials on ado.net), but it's not the MVC way. The MVC way is to use some sort of ORM (Object-relational mapping) such as NHibernate, Subsonic or Linq for SQL.
how to connect to DB without wizard and call procedures and query tables.
To call a procedure (here it will return no result, just perform some action):
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection .Open();
using(SqlCommand command = connection.CreateCommand(nameofthestoredprocedure))
{
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddWithValue("#someparameter", somevalue);
maCommande.ExecuteNonQuery();
}
}
You can put your connection string in the config, just like you're used to.
You can call procedures the same way you would from any .Net application too. #svinto's advice about using an ORM is another way of doing things and is well worth looking at too. Many of the good examples for ASP.Net MVC use the ORM techniques.
If you don't want to go down that route, you might benefit from creating a seperate class library project that you reference from your MVC application. Your Class Library project can act as your data access layer (DAL) where you handle db calls, etc...
Your Controllers can then call your DAL and processing methods to populate entities for the Views.
Ahmy, I think the best advice to give would be before you start off developing using the MVC framework is to have a look into the principles behind the MVC pattern and domain driven design.
Specifically , have a look at repository patterns etc.
You can still add connection strings to your web.config in a block and access them as you would have done in a webforms project, after all Asp.net MVC is based on webforms. Its just likely that you wouldn't really want to do this if you're utilising MVC the way it was intended, its all about seperation of concerns.
www.asp.net has some great intro. examples worth watching.
Try downloading NerdDinner, or even better ... ContactManager iteration 1 (the tutorial directly answers your Q). Those should give you a good idea for how to handle database access. I wouldn't suggest looking at something like Oxite or MS StoreFront though, as these are a bit more complex.
To specifically answer your question: the connection string, like in ASP.NET, can go in your web.config or hard-coded in your application.

Resources