Best way to connect database for asp.net mvc - sql-server

I want to know different options available when we are connecting asp.net mvc application to database.
What are pros and cons of each method and what is best method to choose.
In Traditional asp.net web form application i am using DAL approach, which seems to be very useful to me so far even while dealing in shared hosting environment. I want solution which i can apply in shared hosting environment.
Thank you everyone :)

On the website Mikesdotnetting.com, there is an article titled ASP.NET MVC is not all about Linq to SQL. Basically what the article talks about is taking a standard ASP.NET web forms n-layered application and moving it into the world of MVC. The only things that are changed are the actual web forms into views. He leaves much of the application as is, the data access layer, the entity objects, the business rules, etc. From reading the article and seeing what you're asking, I think you can easily use what you know (your DAL) and combine that with MVC.
Good luck on your project, and hope this helps some.
Original Web form based application article:
Building Layered Web Applications with Microsoft ASP.NET 2.0

I use the the following for the data access:
Entity Framework (Code First)
Windsor Container for dependency injection set up with the repository pattern to make my controllers testable without having a database.
Blog post using EF Code First with MVC
Explanation Repository Pattern
Blog post about using MVC3 and Castle Windsor

There are different Ways to Connect to Databases for ASP.NET MVC web application using ENTITY FRAMEWORK :
Code-First
Db-First
Model-First
Code First approach lets you generate databases and datasets automatically .
Use it if you are developing a large Web application and expecting changes of the Models in Future. So you can alter a database after making changes in the Code Accordingly.
Db-First lets you generate models automatically giving good control over Databases. Make sure there is a Database Admin working in the application.
Model-First Approach is not good option as developer would not be having control over both Model and Database.

Related

MVC with AngularJS and node js

I have been wondering whether this combination of technologies would work. I can implement a modular web application with MVC, EF, and utilize AngularJs if I would want to play around with the technology to implement sort of a mini SPA. I would like to extend my knowledge a bit further, and I was wondering whether I could utilize node.js instead of EF for relational database communication. Can I intermingle MVC back end with AngularJs for front end (mixed with MVC), and node.js for database communications
Is it possible? Yes, technically, but it would be very bad practice.
ASP.NET's MVC does nearly everything server-side. This means that views are built within the server and sent to the user. The controller is also server side.
With AngularJS, this paradigm is flipped on its head. The controller and view are both client side. The server sends the user all of the views and controllers at once, and then from then on only serves data. This is very attractive for single-page applications, and sites that want to exchange data, but not have to constantly send a new view. NodeJS is a popular architecture to use for the server, but any server architecture will work fine with Angular.
Both systems have their pros and cons, but there is no sane reason I can think of to use them together. You can certainly use ASP.NET as the server/model for an AngularJS application, but I'd discourage you from using APT.NET MVC with Angular.

ASP.NET MVC 5 / WebAPI 2 / Xamarin / AngularJS / Solution Visual Studio

I have currently a visual studio that contains 3 projects :
MyApp.Models : Contains all my models with Code-First migrations
MyApp.Web : Contains my main website, only with MVC
MyApp.Pass : Contains a subdomain website, for customers.
We have new projects and we need to have those things :
A WebAPI that can be consumes by my main website, my pass website, a backoffice website, and a mobile application
a backoffice website that consumes WebApi, built with AngularJS
A mobile application that consumes WebApi, built with Xamarin
How can i layer my visual studio solution to only have one WebAPI that can be consume by all my differents websites/mobile app ?
Best regards,
I am currently building a side project - viewingbooker.com which is exactly the setup you are looking for.
What you need to bare in mind is that web api and mvc website have 2 different authentication techniques. Web Api 2 makes amazingly easy to authorise users from eg. xamarin mobile apps. Token is issued and is generally valid for 14 days of inactivity.
I have few projects within my solutions. Most importantly you need a separate project for your business logic. I also use DI to test my business logic as I go.
For website, I serve data as JSON from standard Controllers. For my mobile app, I have a separate web api project that serves the data separately. They both use business logic project so it keeps code redundancy to the minimum.
Remember that mobile app is not a website which you can quickly fix. If you end up using the same models and controllers for website and mobile apps, any change you make will brake your mobile apps and not all users have auto upgrade feature switched on on their mobile devices.
So I recommend you have a standard website with its own models and controllers, which is consumed by angular/knockout etc. Web API 2 project with its own models and controllers. Business logic project in the form of different services accessible by its interfaces so it's easier to test it. And don't get too paranoid with code redundancy that is different controllers, models for website/mobile. This approach will save you a lot of headache in the future - talking from experience.

What are the limit of Drupal or any CMS in general?

Drupal is a CMS, not a web framework.
Does this mean it should only be used for publishing posts, blogs, graphs or what ever content you can think of or can it be used for more sophisticated applications with 'true' business logic behind the scenes ?
Can it be used for developing a resource management application? Can we extend the Drupal database with our own tables that represent business objects?
You should be able to extend Drupal with custom modules to achieve your business goals. I wouldn't add onto the Drupal database adjusting it's schema since that would make patching and upgrading difficult to say the least. You could use an additional database if needed if the existing Drupal database API doesn't meet your needs. There is also a Drupal services module available (https://drupal.org/project/Services) that you could use for a web API interface between your app and Drupal to access it's objects.
This Stackoverflow post also may provide some answers, Web application integration with Drupal -- I have been involved with successful back-office business applications that utilize a CMS such as Drupal extending it using custom modules and an additional database for custom data objects.

How to communicate between the viewmodel and model if model is in separate project in WPF client application?

I am new to WPF and Entity Framework. I am planning to follow MVVM pattern in a WPF client application and Entity Framework for model. For security reasons I don't want to include the entity framework reference in the client application. I have the following query on this front.
In the above case which is the best way to communicate between viewmodel and model?
Well if you really want to separate the application layers that hard, you could create a WCF Service, which loads the entities from the data source and passes it to the client.
You can find some information on creating a WCF Service here. For information about consuming such services you should have a look here. But you will find many articles in the WWW.

ASP.Net MVC AND WPF wioth probably Windows 8 Phone

I am currently developing an application that utlises telerik ORM tools to manage access to a back end database. On top of this layer I am implementing a Business Layer(domain) containing the real world objects that represent my application model.
So far so good.
The issue I have now is one of serious confusion. I will be developing a ASP.Net MVC web site that forms the main hub of my application. In addition to this I have the requirement to create a WPF application that implements some integration into the desktop and lastly I would like to implement a Windows 8 phone app containing a subset of the ASP.Net website functionality but that will also implement some of the WPF functionality.
The problem is I would like to keep the application as simple as possible and maintain a high level of code reuse. Ideally I don't want to implement multiple business layers but I'm not sure of what architectural patterns would be best used? I think adding some kind of service - be it REST, Web services, WEB API or something on top of the business layer and then dealing with each UI technology independently will be the way to go but I thought I'd ask for opinions and advice before I head down a route and end up back tracking?
You could use WCF or Web API as the layer that sits on top of your business layer. If you're looking to use RESTful api, then the new Web API is a good place to start.
If you take a look at these tutorials, they should help: http://www.asp.net/web-api/samples
Your client applications would then call into these API's to communicate with your business / data layer.

Resources