Data Access in ASP.NET MVC 3 - sql-server

What's the recommended way of creating a Data Access layer in real-life ASP.NET MVC applications? Is it EF? Ef Code First? NHibernate? Any other idea?
Thank you & regards

There is no recommend way.
I prefer EF Code First for doing this because
the Sourcecode is very clean and easy to read
It is easy to simple change the connectionstring and generate a new database if not already exists
easy to migrate your Database if your Model has changed (no need to recreate the Database) using EntityFramework.SqlMigrations
if your Database already exists you can use the Entity Framework Power Tools to generate the Models and Database context from your existing Database

It all depends of your need:
NHibernate is a more mature ORM with a big community
Entity Framework is now getting very well supported and you can find also great information (check Julie Lerman blog)
Both support code generation from database.
Code first: allows you to create your database schema from your domain models. This is great if you don't want to bother with database. NHibernate can do it also.
To help you decide which way to use Entity Framework
Source
There are many other great ORM:
Subsonic
Stackoverflow's ORM Dapper if performance is an important criteria there is a small benchmark on the site

If you're partial to the MSFT tooling and wanting to be "modern", then EF Code First is probably the place to start. One example worth perusing: https://github.com/NuGet/NuGetGallery .

I like to use Model First because it allows me the most freedom to design and implement in my opinion. It also makes it very easy to change the database design.

There is none, stackoverflow is full of people who have gone down the various routes, so you can get help no matter which choice you make.
Best advice, try doing a few small exploratory webs using a couple of approaches which seem to stand out.

The MVC gurus (the people who wrote MVC) at MS all seem to use Entity Framework at the moment. having said that you can use any ORM (or really any data access tech you want) as MVC doesnt actually specify anything at all about the way you access data

Try LINQ, most MVC products I see make use of LINQ.

Related

Database first ORM

I am currently about to start out on a project to convert a legacy access front end application using MSSQL backend database to WPF using the MVVM pattern.
The database has around 300 tables so it will need to use and ORM tool to generate the POCO classes using database first driven design.
I have recently receiving some mentoring for the project and nHibernate has been recommended as the ORM over Entity.
Looking to find out your recommendations and whether we should be looking to Entity or another ORM as opposed to what is possibly just the one that the mentor has experience using?
Thanks in advance,
I'm using NHibernate everywhere. On .NET Core, on .NET Framework, since 2009. Only some projects that are not permitted use of NH i've used EF or other orm or some like this (Linq for SQL or DAAB stuff).
NHibernate provide more control, more configuration spots and more features instead EF. It's my recomendation in all scenarios that be use a ORM. Dapper solve some questions too.
But if i have NH i don't need Dapper because we have some types of operate with database.
More options, more responsability. NHibernate is more complex. Needs a deep drive into your complexity to understand how give best performance and approach to solve any kind of database interaction. Do you do more, but you must know to do.

Why use Doctrine instead of CakePHP's standard database ORM?

I've about to start work on a new web project using CakePHP 2.2, having mostly worked with Zend Framework 1 previously.
On first look, I really like the way CakePHP handles models and the underlying database tables, especially with regard to getting one-to-many and many-to-many relationships setup quickly with the minimum of fuss. It seems, quite frankly, a breath of fresh air compared to how I used to do things in Zend Framework.
However, over the last few years whilst using Zend Framework, I had looked at using Doctrine to provide the model relationships that ZF was rather clumsy at doing. Doctrine looked to me to be very powerful and flexible.
So now I am wondering, before I get too deep into my new CakePHP project, should I still consider using Doctrine with my new choice of framework? What advantages and disadvantages does Doctrine bring to the table (no pun intended!) compared to CakePHP's built-in ORM and database functionality?
CakePHP works best if used as a whole. In your specific case though you can use Doctrine instead of Cake's ORM if you like but you will lose lot of features of cake. For eg. the FormHelper does lot of things "magically" like guessing proper input type for fields etc. using the model's schema, automatically showing error message below appropriate fields in forms when validation fails, etc.
As you commented you don't have much experience with Doctrine either so I would suggest sticking to CakePHP's ORM and look for option only if you find it inadequate for your needs.
If you have already worked with Doctrine and CakePHP's ORM, you can decide based on the main reasons to change:
What will give you more productivity?
What will give you more maintainability?
What will give you less learning curve?
Personally, I would choose Doctrine, based on the fact that it is really specific to one problem.

Picking an ORM tool - So many choices, and so little time

After much reading, playing and fiddling, I am still not sure what ORM tool is the one i should be using above others.I am usign the Dotnet stack.
I have looked at:
Entity framework
LLBLgen Pro
NHibernate
Currenlty I am rather impressed with LLBLGen Pro.
I have also read about Castle's active record, sub sonic and Linq to SQL.
Why should i use one over the other and what are the pitfalls of using this one over that one?
How should i try and make the informed desicion.
I am concerened about some large gotcha that i might not see at this stage that will only come to life far into the development cycle and then have cause major hassles.
Thanks for all the help.
I have used both NHibernate and Entity Framework and both are great. If you like a more drag-and-drop approach, entity framework is the best choice and maybe the easiest to get started with. If you need a ORM for a commercial product maybe it's easier to sell EF (because Microsoft is behind it). At least that is my experience. But, I'm using HNibernate at my current project (at a customer) and we are very pleased with it. It has a bit of a learning curve, but once you get the hang of it it's pretty productive to use. The only drawback is the XML hacking you have to do. If you have the possibility to use EF 4 I think that would be my recommendation. If not, go for NHibernate.

Creating web forms from a database schema

I'm wondering if there are any applications, preferably freeware, that can take a database configuration, and, with as little hassle as possible, create web forms for inserting data easily.
I'm finding it hard to express exactly what it is I'm after. Maybe I can talk a bit about what I need.
I have a configuration database that, at least usually, contains "the truth" about the servers in our system. It contains stuff like zone names, hostnames, different configuration items, etc, over multiple tables. Right now we're using simple INSERTs directly when adding new servers or other stuff, handling the keys and IDs ourselves. The crux is, they don't want us to develop a simple web form thingy to handle this, instead they want a tool that can generate the web form thingy. Did that make sense?
I'm not sure if anything like this exists or is reliable, but, I thought that if anyone knew, it's this community. Thanks!
As many have already stated, it depends on what technology you're working with:
.Net 3.5 - Dynamic Data or Subsonic's Scaffolding control
.Net 2.0 - Subsonic's Scaffolding control
PHP - CakePHP
Ruby - Rail's Scaffolding component
"with as little hassle as possible"
have you checked things like PHP/MySQL Web Database Application Code Generator 10.02 ?
or phpmyedit ?
seems to me that what everybody else proposed so far requires a fair amount of coding...
Also, have a look at phprunner. It is not free, but looking at the screenshots, it seems to fit your requirements.
ASP.NET has Dynamic Data, that I think fits your description.
There's also SubSonic. Both are free and open source.
Tried Dynamic Data?
Besides ASP.NET dynamic data, you could also have a look at SubSonic
With PHP, if you have the ability to name the tables and columns as you see fit, you could try CakePHP framework, and specifically the scaffolding feature. With scaffolding turned on, the code will create CRUD forms from the schema for you.
Here's the link for learning about SubSonic & Scaffolding http://www.subsonicproject.com/web-forms-controls/the-scaffold/
, enjoy ;)
One more link from the SubSonic forums http://monk.thelonio.us/post/Scaffold-Enhancements-in-SubSonic-21.aspx
You can try Adminer Editor
Adminer Editor is both easy-to-use and user-friendly database editing tool written in PHP. It is suitable for common users, as it provides high-level data manipulation.

Anyone know of a simple WPF/Silverlight data access framework?

Does anyone know of a simple WPF or Silverlight framework which enables you to e.g. define some database tables in e.g. SQL Server compact database and then the framework automatically creates the Window classes etc. which allows a user to login and edit that data?
I'm not looking for a complicated MVVM pattern example, it can be hard coded, it should just save the developer the time of creating all the CRUD code and forms and authorization necessary for users to edit the data. The developer could define 10 database tables, run the code generation, and then be pretty much 80% finished with any simple database application he wanted to make.
All of that would be generic code so I would think some framework like this would exist or someone would be working on some open source project like this already.
Does anyone know of a framework or tool like this?
It's not Silverlight, but ASP.NET Dynamic Data sounds like it would do what you're asking. It provides a web-based front end for editing database tables.
I've used it for a small project and you can literally have it up and running with CRUD functionality within an hour.
maybe you should take a look at the Sculpture project. There might be something you are looking for.
Since you cannot have direct connection to a database server with Silverlight, you should look at a .NET data access framework using the regular .NET Framework thru a Web Service.

Resources