How to do deal with an evolutionary design of a web-site database? - asp.net-mvc

I am about to start my first project on an ASP.NET MVC 3 web-site. This site will have data storage and I am wondering what's the best way to deal with the evolutionary design of the database behind the web-site - after the site launches, it will be extended and it will keep on growning thus database refactoring will be an issue. What's the best way to deal with this "problem"? I was thinking of using an ORM like NHibernate or Entity Framework, but neither of them support evolutionary database design.
Any help is appreciated.

Are you looking for migrations support for .NET primarily?
https://stackoverflow.com/questions/313/net-migrations-engine
https://stackoverflow.com/questions/8033/database-migration-library-for-net
.NET migrations: Setup and migrate multiple databases at runtime
I can assure you that developers are doing evolutionary database design with both NHibernate and Entity Framework, so it's entirely possible. Maybe you want a highly tooled, automated process though?

Related

Are there any multi-database multi-tenant ASP.Net MVC reference applications

I'm currently building a multi-tenant, single code-base MVC app hosted on Windows Azure and have come up with my own application framework work to support it.
Although it works I'm still not a 100% happy with it and I was wondering if anyone knew of a good example of multi-database,single code base out there ?
I'm not sure about the multitenancy, but KiGG is really nice example of domain driven design and application supporting multiple databases. It doesn't use multiple databases at the same time, but they way the layers are designed allows very nice extensibility, for example for caching or logging.
I think the design approach of KiGG is very good for multitenancy too, and even if it doesn't answer your question completely, I think it is worth of reading the code anyway.

Performance reprogramming website in MVC3 with Entity Framework

At the moment I have a fairly big website with about 10k visitors a day.
This is a community website with news/blogs/videos and a big forum.
This all runs on a self made PHP5 application which performance faily well, has good performance. The database is a MySQL5.1 database.
Now I am getting fedup with PHP and the loose typed framework, lack of namespacing and a proper MVC setup, so I am thinking of rewriting the site in MVC3 ASP.NET.
Now I have experience with this, but not in the MVC framework yet, and I have a few questions about the performance, especially the Entity Framework:
Is it even worth using the entity framework? Will it cost alot of overhead and performance degration? I am not sure yet if I should switch to MSSQL.
Entity Framework was not performance optimized as far as i have worked with it. That is not it's primary goal by design. Performance is important of course, but EF is at most easy to use, and start with. It provides an fast way integrate with existing database, or create database really, really fast. Performance is not the primary goal, but improving indeed.
Here is an good chart with some benchmarks from the Microsoft team, that can be a ground for making the decision.
As you can see, there is a dramatic performance improvement from .NET 4.0 to 4.5 as far as it comes to "LINQ to Entities". It still seems twice slower than direct SQL though. LINQ to SQL is the slowest operation of course.
ASP.NET MVC is an good direction, especially if you want to try something different. EF is not the best you can do if you pursue performance. Writing the business layer on your own, including the SQL stored procedures would be better, but will require a lot more time.
When using an ORM like EF or NHibernate you always have to live with the trade-off between performance and convenience. If you can live with a relatively bad performance (I think it should be possible to run your site w/ an ORM) NHibernate should your first choice, from my point of view it is more mature while EF is still lacking provider support and has some shortcomings with respect to the develevopment workflow (which you possibly expect when using NHibernate but not when using a MS tool).
If you switch from PHP to .NET you should consider switching from MySQL to MSSQL, just because it fits perfectly into the MS ecosystem (and performance/scalability should be improved too, this could possibly outweight the performance degradation you expierence when using an ERM).
You could also take a look at LINQ which could be an alternative between a classic ORM and hard coded SQL commands (also with respect to the performance, LINQ to SQL is pretty fast and you can also use LINQ to Entitiy Framework when using EF (thats pretty slow)). LINQ would fit your needs if you want some level of abstraction wihtout the need of endless configuration and if you like RAD (who doesn't?).
In general the performance of ASP.NET MVC3 is quite good, but you should know that you need some experience to tweak your application and avoid (common) pitfalls. Cutting a long story short: You should be easily able to write an ASP.NET application that has a better performance than a scripted PHP page (by design)
But you should also know, if you decide to commit yourself to the MS ecosystem (.NET, MSSQL w/ LINQ/EF) its hard to break out and providers for LINQ and EF for non-MS RDBMS might cost some bucks (check www.devart.com).
Hope this gives you some guidance
Further reading:
ORM wars: Comparing nHibernate, LINQ To SQL & the Entity Framework
NHibernate vs Entity Framework: a performance test
NHibernate vs. Entity Framework 4.0
This is way too much of a general question, and there's no good answer to it. I highly recommend that you perform some tests using the Entity Framework as well as MVC3 and see that it meets your needs.
Also, and not to be condescending, but 10K visitors a day is not that much compared to other sites out there that are succesfully running ASP.NET MVC and Entity Framework.
In the end, I'd say it most definitely will meet your needs, but as with any project that scales, you will have to be aware of bottlenecks in your particular app and come up with solutions to address those bottlenecks.
This is 100% dependent on the queries.
I've worked on sites with 22 million a month with Nhibernate and about 10 million a month with Linq to Sql.
The queries that performed the slowest were always those weird aggregate quintuple join monsters. ORMs get you 95% of the way there. The rest you'll have to optimize. No ORM gets SELECT * FROM table wrong. Its the outliers that matter.
This will probably get closed as subjective/argumentative in the next five minutes, but I'll give it a shot:
You'll hear a lot of differing views regarding EF and other ORMs, but my personal view is that they cause more problems than they solve. Queries should be kept in the database, where they belong. Proper separation of concerns (SQL code in the database, app code in the project) saves you a lot of problems long-term.
Think of it this way: if your queries were all in stored procedures, you wouldn't even be thinking about migrating/rewriting them at this stage. You could focus on implementing the web side of your app instead of worrying about how to transition your SQL code.
So, skip EF for now, focus on what you know.

Starting a new project - where do I start?

I am going to start a project of my own, which will be ASP.NET MVC + Fluent NHibernate. I want to use test-first approach as much as I can. So, where exactly do I start from? Database schema? Domain model? Mapping domain model classes to the database?
If you have little experience in writing tests, it's the easiest to start from the domain model (or a higher level just below the UI). When you have driven the design of the domain model with TDD, then you will know that what the database schema needs to be like. It may be good to postpone introducing a database to the system, because dealing with database schema migration will add some overhead to the development. And that will also lead to a better design, because then the domain model will be better decoupled from the database layer.
If you are skilled in writing tests and in TDD, it may be beneficial to start from an end-to-end test (in this case they would be written against the web UI) and produce a thin slice of functionality which touches all architectural parts of the system (as recommended in GOOS). In other words, create a walking skeleton. The benefits from this approach are that (1) you will be able to tackle and solve integration problems right at the start, (2) when the end-to-end tests are used to drive the design, it can help you to avoid implementing superfluous parts, and (3) the difficulties of writing the end-to-end tests pressure you to improve the architecture and add monitoring hooks, which may also be useful in monitoring the system in production. (Focused unit test will still be needed, because they provide design pressure at the class level, plus they run faster and thus provide faster feedback.)
I've written more about this latter approach at Design for Integrability.
Requirements gathering.
Start with a mock/prototype (e.g. Balsamiq Mocks) of the application, then writre the views, mocking controllers as you go along, then write the controller logic, mocking the DAO/Repositorys along the way. By the time you start writing your DAO/Repositories, you'll have a good idea of your your required domain objects. Knock those out and use Fluent Nhibernate to build your database.
At least that's they way I'm trying to do things.
I recommend you S#arp Architecture Project that uses best practices combining:
NHibernate
FluentNhibernate
TDD / DDD with model firts approach with Sqlite database for unit testing
Mocking
Repository pattern
You can also install S#arp arch. template for Visual Studio IDE.

ASP.NET MVC with Postgres; ORM recommendations?

I'm project managing an intranet application being developed at work. We're in the early planning stages. I've previously done all my development in Python using Django, but as we're a windows shop we're probably going to go with ASP.NET MVC.
We won't really be able to afford a SQLServer license though, so we were perhaps looking into using Postgresql. However I can't seem to find many examples or guides for people who want to utilise a third party ORM - or at least, an ORM with similar usage as Django - that works with Postgresql.
Ultimately we'd like to handle authentication via Active Directory [including groups], but store actual content within the db.
There have been previous questions of a similar nature, but most of them are over a year old when MVC was stil in Beta.
Any ideas?
NHibernate by a country mile.
It also supports MySql and should you want to change it has the main commmercial ones too. Haven't switched between db vendors but if you don't do much bespoke t-sql and say use fluent nhibernate you could almost plug and play between database platforms.
The support and community behind NHibernate when it comes to Mvc is second to none. It is categorically the ORM of choice.
You can try DataObjects.Net - open source ORM with GPLv3 or commercial licenses. It also supports Postrges.
NHibernate supports PostgreSQL. See http://vampirebasic.blogspot.com/2009/02/nhibernate-with-postgresql.html for some advice on how to integrate the two.
Also worth mentioning is that NHibernate now supports LINQ syntax. See http://ayende.com/Blog/archive/2009/07/26/nhibernate-linq-1.0-released.aspx for more details.
I'd recommend Mindscape LightSpeed. It supports PostgreSQL and has a visual designer baked into Visual Studio with full database round tripping to PostgreSQL.
When there was no add-in for Visual Studio to support PostgreSQL from the Server Explorer the guys wrote a free visual studio add-in for supporting it.
Solid O/R Mapper with LINQ mixed with first class visual model development against PostgreSQL. It is a commercial product however there is a free edition for small databases.
Mindscape LightSpeed O/R Mapper
Try Devart LinqConnect - http://www.devart.com/linqconnect/. This Framework supports PostgreSQL, Oracle, MySQL, SQLIte.
Unfortunately, most answers you get on a question like this are going to be based on the responder's opinion and experience and not based on yours.
Most of the suggestions here are good... however... if you are looking for a lightweight/fast ORM that is similar to Django, JackD has the right solution (LinqConnect)...
I've used most of the solutions listed including Django, and find that I usually pick LinqConnect if I'm looking for fast, lightweight and easy. For heavier (read larger) projects I would use something more robust like NHibernate.
But to answer your question correctly... the closest match and least learning curve for someone using Django would definitely be LinqConnect.

What ORM should I use for a ASP.Net MVC project?

I am starting a new ASP.Net MVC project and was wondering what is the best Model approach to take.
Most demos recommend LinqToSQL but I know Microsoft are not really enhancing this product and are focusing more on the Entity Framework.
I like the Subsonic approach but I thought this was going to be built in with MVC with version 3 but there has been no news about the development stage of this project so I am a bit wary of using version 2 if there is to be a new release soon.
I have heard of NHibernate and Castle Record but have not had any experience at all with these and have heard numerous pros/cons for both.
Any help would be highly recommended!
nHibernate learning curve is higher but worth it. Use Fluent nHibernate to ease the pain a bit. nHibernate is less visual that some ORMs but that is really only an issue when you are beginning and once you have experience with it the lack of visual designer is a benefit IMO.
For SubSonic, Rob just release an new MVC template which you can use when starting a new project that bakes a lot of good stuff into a new MVC project including a pre-release of SubSonic 3. Detais are available on Rob Conery's blog.
LLBLGenPro works great for me. It is the best .net ORM out there. I'd avoid Linq to Sql because you'll have problems once the project grows and it is rather weak in features (besides the obvious downsides, like works only with SQL Server, etc.)
I use linq2sql and I think it works absolutely great if you use MSSQL as your database (it works on other databases too, but it requires some 3rd party tools). Yes, Microsoft has 'discontinued' its development, but it is mature enough for the average project. I doubt you will run into any walls. If you're starting a big project that you need to support for years to come, then the Entity Framework might be more suitable.
I personally haven't used NHibernate and Subsonic before, but like Craig says, the learning curve of NHibernate is a bit more steep, though it is supposed to be a great framework (everything from what I heard or read).
If you're willing to spend some money or have a smaller project I'd at least try out LightSpeed. I found pain points withe very ORM I've ever tried and I'm currently using LINQ to SQL myself.
LightSpeed is pretty feature rich though the LINQ support is missing a few features nothing major that can't be worked around. It's pretty close to being the same as LINQ to SQL and LINQ to Entities but has a few more features like Full-text Search.
Castle ActiveRecord works really well for small-to-medium projects based on MVC - I'm using it on a couple of projects at the moment and finding it a very good fit with ASP.NET MVC.
It's an implementation of the active record pattern that uses NHibernate under the hood - in other words, as long as you're happy having one class per database table, it'll do most of the NHibernate configuration for you, leaving you free to write code like:
Customer bob = Customer.Find(/* customer Id goes here */);
bob.FirstName = "Robert";
bob.Save();
Invoice newInvoice = new Invoice();
newInvoice.Products.Add(Product.Find(/* product ID goes here */);
bob.Invoices.Add(newInvoice);
bob.Save();
with very little explicit NHibernate configuration (assuming you have Customer, Invoice and Product tables in your DB, of course)
Because it's NHibernate under the hood, migrating to NHibernate if you need to should be straightforward - you'll already have all the necessary references and libraries. There are a few aspects of NHibernate behaviour that you can't ignore (like session scopes and flushing) - but it's not too hard to work out what's going on with these, and using them in ActiveRecord will give you a head start if/when you need to move to using NHibernate directly.
We're using Fluent + NHibernate here, it works pretty well. Some alternatives that mesh well are SubSonic, Entity Framework, and Linq to SQL. I think straight NHibernate is a bit more cumbersome than it is worth, but is a great underlying layer with Castle ActiveRecord, and with Fluent.
I worked with a product called netTiers (http://www.nettiers.com/) on a project and that worked very well. It's a CodeSmith script that generates business objects from your database tables, views and stored procedures.
If it's not a huge project, I'd use Linq To SQL. If you need all the bells and whistles, bone up on nHibernate and have at it. I don't think you'd run in to any serious issues one way or the other.

Resources